-
Notifications
You must be signed in to change notification settings - Fork 0
/
configurationRoot.go
60 lines (52 loc) · 1.4 KB
/
configurationRoot.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
package goconf
var _ Root = (*ConfigurationRoot)(nil)
type ConfigurationRoot struct {
Providers []Provider
}
func NewRoot(providers []Provider) *ConfigurationRoot {
return &ConfigurationRoot{
Providers: providers,
}
}
func (root *ConfigurationRoot) GetProviders() []Provider {
return root.Providers
}
func (root *ConfigurationRoot) Reload() error {
for _, provider := range root.Providers {
err := provider.Load()
if err != nil {
return err
}
}
return nil
}
func (root *ConfigurationRoot) GetString(name string) (string, bool) {
return GetConfiguration(root.Providers, name)
}
func (root *ConfigurationRoot) GetExtracted(name string) (*ExtractedValue, bool) {
return GetConfigExtractedValue(root.Providers, name)
}
func (root *ConfigurationRoot) GetSection(name string) Section {
return NewSection(root, name)
}
func (root *ConfigurationRoot) GetChildren() []Section {
return GetChildrenFromRoot(root, "")
}
func GetConfiguration(providers []Provider, name string) (string, bool) {
for i := len(providers) - 1; i >= 0; i-- {
provider := providers[i]
if val, ok := provider.GetString(name); ok {
return val, ok
}
}
return "", false
}
func GetConfigExtractedValue(providers []Provider, name string) (*ExtractedValue, bool) {
for i := len(providers) - 1; i >= 0; i-- {
provider := providers[i]
if val, ok := provider.GetExtracted(name); ok {
return val, ok
}
}
return nil, false
}