From 9d9cd1d3b93613071d1dffc1c82c4515d2a65af6 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 21 一月 2020 17:22:39 +0800
Subject: [PATCH] bug fixed  change real fetcher ip

---
 util/common.go |  106 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 61 insertions(+), 45 deletions(-)

diff --git a/util/common.go b/util/common.go
index 8fe6ab2..93ada39 100644
--- a/util/common.go
+++ b/util/common.go
@@ -1,49 +1,17 @@
 package util
 
 import (
+	"fmt"
+	"io/ioutil"
 	"os"
 	"strings"
 
-	"github.com/spf13/viper"
+	"github.com/olebedev/config"
 )
-
-// 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 &params
 }
 
 // FindStringInArray find
@@ -75,22 +43,41 @@
 func InitConfig() {
 
 	const (
-		configFilePath = "/opt/vasystem/config/"
-		configFileName = "pro"
-		configFileType = "yaml"
+		configFileName = "pro.yaml"
 		LOGBASEPATH    = "/data/disk1/valog/"
 	)
 
-	viper.SetConfigType(configFileType)
-	viper.SetConfigName(configFileName)
-	viper.AddConfigPath(configFilePath)
-	viper.AddConfigPath("./")
+	configFilePaths := []string{
+		"/opt/vasystem/config/",
+		"./",
+	}
 
 	LogFile = "./log/analysis-"
 
-	if err := viper.ReadInConfig(); err == nil {
+	var file []byte
+	var err error
+	var fileName string
+	for _, v := range configFilePaths {
+		fileName = v + configFileName
+		file, err = ioutil.ReadFile(fileName)
+		if err == nil {
+			break
+		}
+	}
+	if file == nil {
+		fmt.Println(`Read All Log Config Files Failed, If -logit Use Default, "./log/analysis-[type]"`)
+		return
+	}
+	yamlString := string(file)
 
-		logPath := viper.GetString("LogBasePath")
+	cfg, err := config.ParseYaml(yamlString)
+	if err != nil {
+		fmt.Println("Config Parse File: ", fileName, " Error: ", err)
+		return
+	}
+	logPath, err := cfg.String("LogBasePath")
+
+	if err == nil {
 		if len(logPath) > 0 && IsFileExist(logPath) {
 			if logPath[len(logPath)-1] == '/' {
 				LogFile = logPath + "analysis-"
@@ -103,5 +90,34 @@
 	} else if IsFileExist(LOGBASEPATH) {
 		LogFile = LOGBASEPATH + "analysis-"
 	}
-
 }
+
+// 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-"
+// }

--
Gitblit v1.8.0