-
Notifications
You must be signed in to change notification settings - Fork 48
/
conf.go
55 lines (46 loc) · 1.39 KB
/
conf.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
package agollo
import (
"encoding/json"
"os"
)
// Conf ...
type Conf struct {
AppID string `json:"app_id"`
Cluster string `json:"cluster,omitempty"`
NameSpaceNames []string `json:"namespace_names,omitempty"`
CacheDir string `json:"cache_dir,omitempty"`
MetaAddr string `json:"meta_addr,omitempty"`
AccesskeySecret string `json:"accesskey_secret,omitempty"`
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
Retry int `json:"retry,omitempty"` // retry count. 0 means no retry
SyncTimeout int64 `json:"sync_timeout,omitempty"` // sync request timeout, unit:ms
PollTimeout int64 `json:"poll_timeout,omitempty"` // poll request timeout, unit:ms
}
// NewConf create Conf from file
func NewConf(name string) (*Conf, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
var ret Conf
if err := json.NewDecoder(f).Decode(&ret); err != nil {
return nil, err
}
return &ret, nil
}
func (c *Conf) normalize() {
if c.Cluster == "" {
c.Cluster = defaultCluster
}
if !strIn(c.NameSpaceNames, defaultNamespace) &&
!strIn(c.NameSpaceNames, nomalizeNamespace(defaultNamespace)) {
c.NameSpaceNames = append(c.NameSpaceNames, defaultNamespace)
}
if c.SyncTimeout == 0 {
c.SyncTimeout = 2000
}
if c.PollTimeout == 0 {
c.PollTimeout = 90000
}
}