sunty
2020-04-16 e2ca6ba654f1371f3b375392e29e3fa070ad96ce
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
package config
 
import (
    "github.com/spf13/viper"
    "log"
)
 
type server struct {
    EsServerIp   string `mapstructure: "esServerIp"`
    EsServerPort string `mapstructure: "esServerPort"`
    CoreBaseUnit string `mapstructure: "coreBaseUnit"`
    TimeOut      string `mapstructure: "timeOut"`
    ScriptPath   string `mapstructure: scriptPath`
}
 
type elastic struct {
    IndexName string `mapstructure: "indexName"`
    IndexType string `mapstructure: "indexType"`
}
 
var Server = &server{}
var BasicFS = &elastic{}
 
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", err)
    }
    viper.UnmarshalKey("server", Server)
    viper.UnmarshalKey("elastic.basicFS", BasicFS)
    //fmt.Println(AiOcean)
    //fmt.Println(BasicFS)
}