-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.go
46 lines (39 loc) · 1013 Bytes
/
Config.go
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
package master
import (
"encoding/json"
"io/ioutil"
)
// 程序配置
type Config struct {
ApiPort int `json:"apiPort"`
ApiReadTimeout int `json:"apiReadTimeout"`
ApiWriteTimeout int `json:"apiWriteTimeout"`
EtcdEndpoints []string `json:"etcdEndpoints"`
EtcdDialTimeout int `json:"etcdDialTimeout"`
MongodbUri string `json:"mongodbUri"`
MongodbConnectTimeout int `json:"mongodbConnectTimeout"`
JobLogStoreDb string `json:"jobLogStoreDb"`
JobLogStoreCollection string `json:"jobLogStoreCollection"`
WebRoot string `json:"webroot"`
}
var (
G_config *Config
)
// 加载配置
func InitConfig(configFile string) (err error) {
var (
content []byte
conf Config
)
// 1.读配置文件
if content, err = ioutil.ReadFile(configFile); err != nil {
return
}
// 2.json反序列化
if err = json.Unmarshal(content, &conf); err != nil {
return
}
// 3.赋值单例
G_config = &conf
return
}