forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagollo.go
67 lines (54 loc) · 1.69 KB
/
agollo.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
package agollo
var (
defaultClient *Client
)
// Start agollo
func Start() error {
return StartWithConfFile(defaultConfName)
}
// StartWithConfFile run agollo with conf file
func StartWithConfFile(name string) error {
conf, err := NewConf(name)
if err != nil {
return err
}
return StartWithConf(conf)
}
// StartWithConf run agollo with Conf
func StartWithConf(conf *Conf) error {
defaultClient = NewClient(conf)
return defaultClient.Start()
}
// Stop sync config
func Stop() error {
return defaultClient.Stop()
}
// WatchUpdate get all updates
func WatchUpdate() <-chan *ChangeEvent {
return defaultClient.WatchUpdate()
}
// OnConfigChange when config changed, user code would be called
func OnConfigChange(run func(*ChangeEvent)) {
defaultClient.OnConfigChange(run)
}
// GetStringValueWithNameSpace get value from given namespace
func GetStringValueWithNameSpace(namespace, key, defaultValue string) string {
return defaultClient.GetStringValueWithNameSpace(namespace, key, defaultValue)
}
// GetStringValue from default namespace
func GetStringValue(key, defaultValue string) string {
return GetStringValueWithNameSpace(defaultNamespace, key, defaultValue)
}
// GetNameSpaceContent get contents of namespace
func GetNameSpaceContent(namespace, defaultValue string) string {
return defaultClient.GetNameSpaceContent(namespace, defaultValue)
}
// GetAllKeys return all config keys in given namespace
func GetAllKeys(namespace string) []string {
return defaultClient.GetAllKeys(namespace)
}
// Unmarshal unmarshals the config into a struct. Make sure that the tags
// on the fields of the structure are properly set.
func Unmarshal(model interface{}) error {
return defaultClient.Unmarshal(model)
}