From 716810adb573f7e6b40ab52887b5b158d9824817 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期一, 16 九月 2019 17:04:03 +0800
Subject: [PATCH] 读公共的配置文件

---
 insertdata/config.go           |   62 +++++++++++++++++++++++++++++++
 insertdata/insertDataToEs.go   |   16 +------
 main.go                        |    4 +
 ruleserver/readyDataForRule.go |    5 +-
 4 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/insertdata/config.go b/insertdata/config.go
new file mode 100644
index 0000000..71cd45d
--- /dev/null
+++ b/insertdata/config.go
@@ -0,0 +1,62 @@
+package insertdata
+
+import (
+	"github.com/spf13/viper"
+	"log"
+)
+
+
+
+
+type weedfs struct {
+	Ip string `mapstructure: "ip"`
+	UploadPort int `mapstructure: "uploadport"`
+	VisitPort int `mapstructure: "visitport"`
+}
+
+var WeedFs = &weedfs{}
+
+// wp add es 绱㈠紩 浠ュ強 IP port
+type esinfo struct {
+	Masterip string      `mapstructure:"masterip"`
+	Httpport string      `mapstructure:"httpport"`
+	Shards string         `mapstructure:"shards"`
+	EsIndex  esindexlist `mapstructure:"index"`
+}
+
+type esindexlist struct {
+	VideoPersons   index `mapstructure:"videopersons"`
+	DbTables       index `mapstructure:"dbtables"`
+	Dbtablepersons index `mapstructure:"dbtablepersons"`
+	Personaction   index `mapstructure:"personaction"`
+}
+type index struct {
+	IndexName string `mapstructure:"index"`
+	IndexType string `mapstructure:"type"`
+}
+
+type sopath struct {
+	Ip string `mapstructure:"ip"`
+	Port string `mapstructure:"port"`
+}
+
+var SoPath = &sopath{}
+
+var EsInfo = &esinfo{}
+
+// Init is an exported method that takes the environment starts the viper
+// (external lib) and returns the configuration struct.
+func Init(env string) {
+	var err error
+	viper.SetConfigType("yaml")
+	viper.SetConfigName(env)
+	viper.AddConfigPath("/opt/vasystem/config/")
+	viper.AddConfigPath("")
+	err = viper.ReadInConfig()
+	if err != nil {
+		log.Fatal("error on parsing configuration file")
+	}
+	viper.UnmarshalKey("es", EsInfo)
+	viper.UnmarshalKey("weedfs", WeedFs)
+	viper.UnmarshalKey("sopath",SoPath)
+}
\ No newline at end of file
diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 17f8053..1f53641 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -5,7 +5,6 @@
 	"encoding/json"
 	"errors"
 	"fmt"
-	"io/ioutil"
 	"net"
 	"ruleprocess/cache"
 	"ruleprocess/logger"
@@ -13,7 +12,6 @@
 	"time"
 
 	"basic.com/pubsub/protomsg.git"
-	"github.com/go-yaml/yaml"
 	"github.com/golang/protobuf/proto"
 	"github.com/satori/go.uuid"
 	"ruleprocess/ruleserver"
@@ -32,17 +30,9 @@
 }
 
 func init() {
-	data, err := ioutil.ReadFile("./config/conf.yml")
-	if err != nil {
-		fmt.Println("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err)
-		logger.Error("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err)
-	}
-	c := conf{}
-	//鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷
-	yaml.Unmarshal(data, &c)
-	weedfsUrl = c.PhotoUrl
-	videoPersonUrl = c.VideoPersons
-	personAction = c.PersonAction
+	weedfsUrl = "http://"+WeedFs.Ip+":"+strconv.Itoa(WeedFs.UploadPort)+"/submit"
+	videoPersonUrl = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType
+	personAction = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType
 }
 
 // 浜鸿劯鐨勬暟鎹粨鏋�
diff --git a/main.go b/main.go
index a6bf707..5a4d7ea 100644
--- a/main.go
+++ b/main.go
@@ -30,12 +30,14 @@
 var surveyPort = flag.Int("surveyPort", 40007, "survey port") //蹇冭烦
 var pubPort = flag.Int("pubPort", 50007, "pubsub port")       //鏁版嵁鏇存柊
 var initchan = make(chan bool)
+var env =  flag.String("env","pro","env set")
 
 func init() {
+	flag.Parse()
 	// 鏃ュ織鍒濆鍖�
 	logger.Config("./info.log", logger.DebugLevel)
 	logger.Info("鏃ュ織鍒濆鍖栨垚鍔燂紒")
-
+	insertdata.Init(*env)
 }
 func main() {
 	//fmt.Println("缂撳瓨鍒濆鍖栧畬鎴�",<- initchan)//dbserver鍒濆鍖栧畬姣�
diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go
index f7983eb..e4e21a2 100644
--- a/ruleserver/readyDataForRule.go
+++ b/ruleserver/readyDataForRule.go
@@ -2,7 +2,6 @@
 
 import (
 	"basic.com/dbapi.git"
-	bigCache "basic.com/pubsub/cache.git"
 	"basic.com/pubsub/protomsg.git"
 	"encoding/json"
 	"errors"
@@ -49,8 +48,8 @@
 	if err1 != nil {
 		logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
 	}
-	logger.Debug("鏈満淇℃伅鍜宻erver淇℃伅锛�", localConfig, serverIp, serverPort)
-	bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
+	//logger.Debug("鏈満淇℃伅鍜宻erver淇℃伅锛�", localConfig, serverIp, serverPort)
+	//bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
 	go Push1()
 }
 

--
Gitblit v1.8.0