forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.go
37 lines (31 loc) · 761 Bytes
/
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
package agollo
import (
"encoding/json"
"os"
)
// Conf ...
type Conf struct {
AppID string `json:"appId,omitempty"`
Cluster string `json:"cluster,omitempty"`
NameSpaceNames []string `json:"namespaceNames,omitempty"`
CacheDir string `json:"cacheDir,omitempty"`
MetaAddr string `json:"meta_addr"`
}
// 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 !strIn(c.NameSpaceNames, defaultNamespace) {
c.NameSpaceNames = append(c.NameSpaceNames, defaultNamespace)
}
}