panlei
2019-09-16 716810adb573f7e6b40ab52887b5b158d9824817
读公共的配置文件
1个文件已添加
3个文件已修改
87 ■■■■ 已修改文件
insertdata/config.go 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
insertdata/insertDataToEs.go 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruleserver/readyDataForRule.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
insertdata/config.go
New file
@@ -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)
}
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{}
    //把yaml形式的字符串解析成struct类型
    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
}
// 人脸的数据结构
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初始化完毕
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("本机信息和server信息:", localConfig, serverIp, serverPort)
    bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
    //logger.Debug("本机信息和server信息:", localConfig, serverIp, serverPort)
    //bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
    go Push1()
}