liuxiaolong
2019-09-18 711e90df27648aff82eda78d16dbbc159cceb625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package config
 
import (
    "github.com/spf13/viper"
    "log"
)
 
type server struct {
    Runmode   string `mapstructure: "runmode"`
    JwtSecret string `mapstructure: "jwtSecret"`
    JwtExpire string `mapstructure: "jwtExpire"`
    Url       string `mapstructure: "url"`
    AnalyServerId string `mapstructure: "analyServerId"`
    ImageUrl  string `mapstructure: "imageUrl"`
    PublicDomain string `mapstructure: "publicDomain"`
    NetworkAdapter string `mapstructure: "networkAdapter"`
}
 
var Server = &server{}
 
type weedfs struct {
    Ip string `mapstructure: "ip"`
    UploadPort int `mapstructure: "uploadport"`
    VisitPort int `mapstructure: "visitport"`
}
 
var WeedFs = &weedfs{}
 
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"`
    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{}
 
var DBconf = &database{}
 
type facedetect struct {
    Ip string `mapstructure:"Ip"`
    Port int `mapstructure:"port"`
}
 
type dbpersoncompare struct {
    Ip string `mapstructure:"ip"`
    Port int `mapstructure:"port"`
}
 
type espersoncompare struct {
    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.
func Init(env string) {
    var err error
    viper.SetConfigType("yaml")
    viper.SetConfigName(env)
    viper.AddConfigPath("/opt/vasystem/config/")
    err = viper.ReadInConfig()
    if err != nil {
        log.Fatal("error on parsing configuration file")
    }
    viper.UnmarshalKey("es", EsInfo)
    viper.UnmarshalKey("server", Server)
    viper.UnmarshalKey("database", DBconf)
    viper.UnmarshalKey("weedfs", WeedFs)
    viper.UnmarshalKey("sopath",SoPath)
    viper.UnmarshalKey("facedetect", FaceDetectSet)
    viper.UnmarshalKey("dbpersoncompare",DbPersonCompInfo)
    viper.UnmarshalKey("espersoncompare", EsCompServerInfo)
}