forked from thecodeteam/libstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_config.go
68 lines (53 loc) · 1002 Bytes
/
utils_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
package utils
import (
"fmt"
"strings"
gofig "github.com/akutz/gofig/types"
)
func isSet(
config gofig.Config,
key string,
roots ...string) bool {
for _, r := range roots {
rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
if config.IsSet(rk) {
return true
}
}
if config.IsSet(key) {
return true
}
return false
}
func getString(
config gofig.Config,
key string,
roots ...string) string {
var val string
for _, r := range roots {
rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
if val = config.GetString(rk); val != "" {
return val
}
}
val = config.GetString(key)
if val != "" {
return val
}
return ""
}
func getBool(
config gofig.Config,
key string,
roots ...string) bool {
for _, r := range roots {
rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
if config.IsSet(rk) {
return config.GetBool(rk)
}
}
if config.IsSet(key) {
return config.GetBool(key)
}
return false
}