-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (38 loc) · 932 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"`
WebRoot string `json:"webroot"`
MongodbUri string `json:"mongodbUri"`
MongodbConnectTimeout int `json:"mongodbConnectTimeout"`
}
var (
// 单例
G_config *Config
)
// 加载配置
func InitConfig(filename string) error {
var (
content []byte
conf Config
err error
)
// 1, 把配置文件读进来
if content, err = ioutil.ReadFile(filename); err != nil {
return err
}
// 2, 做JSON反序列化
if err = json.Unmarshal(content, &conf); err != nil {
return err
}
G_config = &conf
return nil
}