-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.go
More file actions
41 lines (34 loc) · 691 Bytes
/
Copy pathstring.go
File metadata and controls
41 lines (34 loc) · 691 Bytes
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
package etcdwatcher
import "sync"
type String struct {
rwMutex sync.RWMutex
defaultValue string
key string
value string
}
func NewString(key string, defaultValue string) *String {
return &String{
key: key,
defaultValue: defaultValue,
value: defaultValue,
}
}
func (p *String) SetDefault() {
p.rwMutex.Lock()
defer p.rwMutex.Unlock()
p.value = p.defaultValue
}
func (p *String) Parse(data []byte) error {
p.rwMutex.Lock()
defer p.rwMutex.Unlock()
p.value = string(data)
return nil
}
func (p *String) Key() string {
return p.key
}
func (p *String) Value() string {
p.rwMutex.RLock()
defer p.rwMutex.RUnlock()
return p.value
}