liuxiaolong
2020-06-05 7c811247ecf143e08c576986a884bedadc57dd66
extend/config/config.go
@@ -1,57 +1,49 @@
package config
import (
   "github.com/spf13/viper"
   "log"
   "github.com/spf13/viper"
)
type threshold struct {
   Value int    `mapstructure: "value"`
   Color string `mapstructure: "color"`
}
type server struct {
   Runmode   string `mapstructure: "runmode"`
   JwtSecret string `mapstructure: "jwtSecret"`
   JwtExpire string `mapstructure: "jwtExpire"`
   Url       string `mapstructure: "url"`
   ImageUrl  string `mapstructure: "imageUrl"`
   PublicDomain string `mapstructure: "publicDomain"`
    ServerName     string `mapstructure: "serverName"`
   Runmode        string `mapstructure: "runmode"`
   JwtSecret      string `mapstructure: "jwtSecret"`
   JwtExpire      string `mapstructure: "jwtExpire"`
   Url            string `mapstructure: "url"`
   AnalyServerId  string `mapstructure: "analyServerId"`
   NetworkAdapter string `mapstructure: "networkAdapter"`
   DeviceNum       string `mapstructure: "deviceNum"`       //设备编号
   DeviceType      string `mapstructure: "deviceType"`      //设备型号
   DeviceSerialNum string `mapstructure: "deviceSerialNum"` //设备序列号
   MasterVersion   string `mapstructure: "masterVersion"`   //主控版本
   WebVersion      string `mapstructure: "webVersion"`      //web版本
   ChannelCount    string `mapstructure: "channelCount"`    //通道个数
   DiskCount       string `mapstructure: "diskCount"`       //硬盘个数
   SudoPassword  string      `mapstructure: "sudoPassword"` //系统密码
   SysThresholds []threshold `mapstructure: "sysThresholds"`
   PTZSpeed      int         `mapstructure: "ptzSpeed"` // 云台移动速度
   PatchPath     string      `mapstructure:"patchPath"` //系统更新包路径
   BakPath       string      `mapstructure:"bakPath"`   //系统更新包路径
}
var Server = &server{}
type weedfs struct {
   Ip string `mapstructure: "ip"`
   UploadPort int `mapstructure: "uploadport"`
   VisitPort int `mapstructure: "visitport"`
}
var WeedFs = &weedfs{}
type redis struct {
   Host     string `mapstructure:"host"`
   Port     int    `mapstructure:"port"`
   Password string `mapstructure:"password`
   DBNum    int    `mapstructure:"db"`
}
var RedisConf = &redis{}
type database struct {
   Drive    string `mapstructure:"drive"`
   Name     string `mapstructure:"name"`
   FilePath string `mapstructure:"filepath"`
}
// wp add es 索引 以及 IP port
type esinfo struct {
   Masterip string      `mapstructure:"masterip"`
   Httpport string      `mapstructure:"httpport"`
   EsIndex  esindexlist `mapstructure:"index"`
   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"`
   AiOcean index `mapstructure:"aiOcean"`
}
type index struct {
   IndexName string `mapstructure:"index"`
@@ -59,28 +51,41 @@
}
type sopath struct {
   Ip string `mapstructure:"ip"`
   Ip   string `mapstructure:"ip"`
   Port string `mapstructure:"port"`
}
type elastic struct {
   IndexName string `mapstructure: "indexName"`
   IndexType string `mapstructure: "indexType"`
}
var SoPath = &sopath{}
var EsInfo = &esinfo{}
var DBconf = &database{}
var BasicFS = &elastic{}
type facedetect struct {
   Ip   string `mapstructure:"Ip"`
   Port int    `mapstructure:"port"`
}
type dbpersoncompare struct {
   Url string `mapstructure:"url"`
   Ip   string `mapstructure:"ip"`
   Port int    `mapstructure:"port"`
}
type espersoncompare struct {
   Url []string `mapstructure:"url"`
   Port int      `mapstructure:"port"`
   Ips  []string `mapstructure:"ips"`
}
var DbPersonCompInfo = &dbpersoncompare{}
var EsCompServerInfo = &espersoncompare{}
var FaceDetectSet = &facedetect{}
// Init is an exported method that takes the environment starts the viper
// (external lib) and returns the configuration struct.
@@ -89,17 +94,15 @@
   viper.SetConfigType("yaml")
   viper.SetConfigName(env)
   viper.AddConfigPath("../config/")
   viper.AddConfigPath("config/")
   err = viper.ReadInConfig()
   if err != nil {
      log.Fatal("error on parsing configuration file")
      log.Fatal("error on parsing configuration file", err)
   }
   viper.UnmarshalKey("es", EsInfo)
   viper.UnmarshalKey("server", Server)
   viper.UnmarshalKey("redis", RedisConf)
   viper.UnmarshalKey("database", DBconf)
   viper.UnmarshalKey("weedfs", WeedFs)
   viper.UnmarshalKey("sopath",SoPath)
   viper.UnmarshalKey("dbpersoncompare",DbPersonCompInfo)
   viper.UnmarshalKey("sopath", SoPath)
   viper.UnmarshalKey("facedetect", FaceDetectSet)
   viper.UnmarshalKey("dbpersoncompare", DbPersonCompInfo)
   viper.UnmarshalKey("espersoncompare", EsCompServerInfo)
   viper.UnmarshalKey("elastic.basicFS", BasicFS)
}