-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_adapter_example.go
77 lines (58 loc) · 1.75 KB
/
data_adapter_example.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
69
70
71
72
73
74
75
76
77
package statsig
import (
"errors"
"sync"
)
type dataAdapterExample struct {
store map[string]string
mu sync.RWMutex
}
func (d *dataAdapterExample) Get(key string) string {
d.mu.RLock()
defer d.mu.RUnlock()
return d.store[key]
}
func (d *dataAdapterExample) Set(key string, value string) {
d.mu.Lock()
defer d.mu.Unlock()
d.store[key] = value
}
func (d *dataAdapterExample) Initialize() {}
func (d *dataAdapterExample) Shutdown() {}
func (d *dataAdapterExample) ShouldBeUsedForQueryingUpdates(key string) bool {
return false
}
type brokenDataAdapterExample struct{}
func (d brokenDataAdapterExample) Get(key string) string {
panic(errors.New("invalid get function"))
}
func (d brokenDataAdapterExample) Set(key string, value string) {
panic(errors.New("invalid set function"))
}
func (d brokenDataAdapterExample) Initialize() {}
func (d brokenDataAdapterExample) Shutdown() {}
func (d brokenDataAdapterExample) ShouldBeUsedForQueryingUpdates(key string) bool {
return false
}
type dataAdapterWithPollingExample struct {
store map[string]string
mu sync.RWMutex
}
func (d *dataAdapterWithPollingExample) Get(key string) string {
d.mu.RLock()
defer d.mu.RUnlock()
return d.store[key]
}
func (d *dataAdapterWithPollingExample) Set(key string, value string) {
d.mu.Lock()
defer d.mu.Unlock()
d.store[key] = value
}
func (d *dataAdapterWithPollingExample) Initialize() {}
func (d *dataAdapterWithPollingExample) Shutdown() {}
func (d *dataAdapterWithPollingExample) ShouldBeUsedForQueryingUpdates(key string) bool {
return true
}
func (d *dataAdapterWithPollingExample) clearStore(key string) {
d.Set(key, "{\"feature_gates\":[],\"dynamic_configs\":[],\"layer_configs\":[],\"layers\":{},\"id_lists\":{},\"has_updates\":true,\"time\":1631638014812}")
}