-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf_group.go
64 lines (52 loc) · 1013 Bytes
/
conf_group.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
package config
import (
"strconv"
"sync"
)
type confGroup struct {
name string
elements map[string]string
mu sync.RWMutex
}
func newConfGroup(name string) *confGroup {
return &confGroup{
name: name,
elements: make(map[string]string),
}
}
func (g *confGroup) set(key, value string) {
g.mu.Lock()
defer g.mu.Unlock()
g.elements[key] = value
}
func (g *confGroup) getString(key string) (string, bool) {
return g.get(key)
}
func (g *confGroup) getInt(key string) (int, bool) {
val, ok := g.get(key)
if !ok {
return 0, false
}
v, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return 0, false
}
return int(v), true
}
func (g *confGroup) getBool(key string) (v bool, ok bool) {
val, ok := g.get(key)
if !ok {
return false, false
}
b, err := strconv.ParseBool(val)
if err != nil {
return false, false
}
return b, true
}
func (g *confGroup) get(key string) (string, bool) {
g.mu.RLock()
defer g.mu.RUnlock()
v, ok := g.elements[key]
return v, ok
}