From 5f9516b33f1d030ce160da709997bdb746b1d57f Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 01 十一月 2019 15:58:35 +0800 Subject: [PATCH] set config --- .gitignore | 2 ++ server.go | 2 +- esutil/EsClient.go | 2 +- extend/config/config.go | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e69de29..9b9a727 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +test.exe \ No newline at end of file diff --git a/esutil/EsClient.go b/esutil/EsClient.go index 6bb4c56..1c8ef97 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -12,7 +12,7 @@ "strings" "sync" "time" - "andriodServer/config" + "andriodServer/extend/config" log "andriodServer/log" ) diff --git a/extend/config/config.go b/extend/config/config.go index d912156..2081b5b 100644 --- a/extend/config/config.go +++ b/extend/config/config.go @@ -1 +1,38 @@ package config + +import ( + "log" + "strconv" + + "github.com/spf13/viper" +) + +type server []ServerInfo + +type ServerInfo struct { + ServerId string `mapstructure: "serverId"` + ServerIp string `mapstructure: "serverIp"` + VideoPort int `mapstructure: "videoPort"` + NginxIp string `mapstructure: "ngxIp"` + NginxPort int `mapstructure: "ngxPort"` +} + +var serverList = &server{} + +var ServerMap = make(map[string]string,0) +var NgxMap = make(map[string]string,0) +func Init(env string) { + var err error + viper.SetConfigType("yaml") + viper.SetConfigName(env) + viper.AddConfigPath("./config/") + err = viper.ReadInConfig() + if err != nil { + log.Fatal("error on parsing configuration file") + } + viper.UnmarshalKey("server", serverList) + for _,s :=range *serverList { + ServerMap[s.ServerId] = "http://"+s.ServerIp+":"+strconv.Itoa(s.VideoPort)+"/getRecordVideoPath" + NgxMap[s.ServerId] = "http://"+s.NginxIp+":"+strconv.Itoa(s.NginxPort)+"/videosource" + } +} \ No newline at end of file diff --git a/server.go b/server.go index 9576560..eb83692 100644 --- a/server.go +++ b/server.go @@ -8,7 +8,7 @@ "time" "andriodServer/esutil" - "andriodServer/config" + "andriodServer/extend/config" log "andriodServer/log" ) -- Gitblit v1.8.0