forked from robertzhouxh/intoyun-enterprise-demo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
96 lines (83 loc) · 2.35 KB
/
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
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
package main
import (
"flag"
"runtime"
"time"
"github.com/Terry-Mao/goconf"
)
var (
gconf *goconf.Config
Conf *Config
confFile string
)
func init() {
flag.StringVar(&confFile, "c", "./intoyun-enterprise-demo-go.conf", " set intoyun-enterprise-demo-go config file path")
}
type Config struct {
// base section
PidFile string `goconf:"base:pidfile"`
Dir string `goconf:"base:dir"`
Log string `goconf:"base:log"`
MaxProc int `goconf:"base:maxproc"`
HTTPAddrs []string `goconf:"base:http.addrs:,"`
HTTPReadTimeout time.Duration `goconf:"base:http.read.timeout:time"`
HTTPWriteTimeout time.Duration `goconf:"base:http.write.timeout:time"`
BucketChannel int `goconf:"bucket:channel"`
SvrProto int `goconf:"proto:svr.proto"`
CliProto int `goconf:"proto:cli.proto"`
// app
AppId string `goconf:"app:appid"`
AppSecret string `goconf:"app:appsecret"`
Debug bool `goconf:"base:debug"`
// push
PushChan int `goconf:"push:chan"`
PushChanSize int `goconf:"push:chan.size"`
// websocket
WebsocketBind []string `goconf:"websocket:bind:,"`
// kafka
KafkaAddrs []string `goconf:"kafka:kafka.list:,"`
SaslEnable bool `goconf:"kafka:sasl.enable"`
SaslUser string `goconf:"kafka:sasl.user"`
SaslPassword string `goconf:"kafka:sasl.password"`
KafkaTopic string `goconf:"kafka:topic"`
Group string `goconf:"kafka:group"`
}
func NewConfig() *Config {
return &Config{
PidFile: "/tmp/intoyun-enterprise-demo-go.pid",
Dir: "./",
Log: "./intoyun-enterprise-demo-go-log.xml",
MaxProc: runtime.NumCPU(),
HTTPAddrs: []string{"8080"},
WebsocketBind: []string{"0.0.0.0:8080"},
CliProto: 5,
SvrProto: 80,
BucketChannel: 1024,
Debug: true,
PushChan: 10,
PushChanSize: 100,
}
}
func InitConfig() (err error) {
Conf = NewConfig()
gconf = goconf.New()
if err = gconf.Parse(confFile); err != nil {
return err
}
if err := gconf.Unmarshal(Conf); err != nil {
return err
}
return nil
}
func ReloadConfig() (*Config, error) {
conf := NewConfig()
ngconf, err := gconf.Reload()
if err != nil {
return nil, err
}
if err := ngconf.Unmarshal(conf); err != nil {
return nil, err
}
gconf = ngconf
return conf, nil
}