-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
62 lines (54 loc) · 1.5 KB
/
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
package singularity
import "sync"
//Configuration interface for getting config values
type Configuration interface {
GetBool(string) bool
CheckBool(string) (bool, bool)
GetString(string) string
CheckString(string) (string, bool)
}
type defaultConfig struct {
sync.Mutex
config map[string]interface{}
}
func (config *defaultConfig) getVal(key string) interface{} {
config.Lock()
defer config.Unlock()
return config.config[key]
}
//GetBool returns the bool value of key, and defaults to false if it can't find key.
func (config *defaultConfig) GetBool(key string) bool {
if val1 := config.getVal(key); val1 != nil {
if val2, ok := val1.(bool); ok {
return val2
}
}
return false
}
//CheckBool returns the bool value of key, and whether or not it actually found key.
func (config *defaultConfig) CheckBool(key string) (bool, bool) {
if val1 := config.getVal(key); val1 != nil {
if val2, ok := val1.(bool); ok {
return val2, true
}
}
return false, false
}
//GetString returns the bool value of key, and defaults to false if it can't find key.
func (config *defaultConfig) GetString(key string) string {
if val1 := config.getVal(key); val1 != nil {
if val2, ok := val1.(string); ok {
return val2
}
}
return ""
}
//CheckString returns the bool value of key, and whether or not it actually found key.
func (config *defaultConfig) CheckString(key string) (string, bool) {
if val1 := config.getVal(key); val1 != nil {
if val2, ok := val1.(string); ok {
return val2, true
}
}
return "", false
}