package util
|
|
import (
|
"os"
|
"strings"
|
|
"github.com/spf13/viper"
|
)
|
|
// GetIpcAddress get ipc
|
func GetIpcAddress(shm bool, id string) string {
|
if shm {
|
return id
|
}
|
return `ipc:///tmp/` + id + `.ipc`
|
}
|
|
// SetParams 收集参数
|
func SetParams(param string) {
|
RunParams = append(RunParams, param)
|
}
|
|
// FillParams 填充MapParams
|
func FillParams(key, value string) {
|
MapParames[key] = value
|
}
|
|
// GetParams 获取slave params
|
func GetParams() *[]string {
|
// if len(RunParams) == 0 {
|
// for k, v := range MapParames {
|
// param := "-" + k + "=" + v
|
// RunParams = append(RunParams, param)
|
// }
|
// }
|
// return &RunParams
|
|
var params []string
|
for _, v := range RunParams {
|
params = append(params, v)
|
}
|
for k, v := range MapParames {
|
param := "-" + k + "=" + v
|
params = append(params, param)
|
}
|
return ¶ms
|
}
|
|
// FindStringInArray find
|
func FindStringInArray(str string, array []string) (string, bool) {
|
found := false
|
ret := ""
|
for _, v := range array {
|
if strings.EqualFold(str, v) {
|
found = true
|
ret = v
|
break
|
}
|
}
|
return ret, found
|
}
|
|
// IsFileExist file exist
|
func IsFileExist(path string) bool {
|
_, err := os.Stat(path)
|
if err != nil {
|
if os.IsNotExist(err) {
|
return false
|
}
|
}
|
return true
|
}
|
|
// InitConfig 读取配置文件
|
func InitConfig() {
|
|
const (
|
configFilePath = "/opt/vasystem/config/"
|
configFileName = "pro"
|
configFileType = "yaml"
|
LOGBASEPATH = "/data/disk1/valog/"
|
)
|
|
viper.SetConfigType(configFileType)
|
viper.SetConfigName(configFileName)
|
viper.AddConfigPath(configFilePath)
|
viper.AddConfigPath("./")
|
|
LogFile = "./log/analysis-"
|
|
if err := viper.ReadInConfig(); err == nil {
|
|
logPath := viper.GetString("LogBasePath")
|
if len(logPath) > 0 && IsFileExist(logPath) {
|
if logPath[len(logPath)-1] == '/' {
|
LogFile = logPath + "analysis-"
|
} else {
|
LogFile = logPath + "/analysis-"
|
}
|
} else if IsFileExist(LOGBASEPATH) {
|
LogFile = LOGBASEPATH + "analysis-"
|
}
|
} else if IsFileExist(LOGBASEPATH) {
|
LogFile = LOGBASEPATH + "analysis-"
|
}
|
|
}
|