-
Notifications
You must be signed in to change notification settings - Fork 10
/
user_persistent_storage_example.go
45 lines (36 loc) · 1.14 KB
/
user_persistent_storage_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
package statsig
import (
"errors"
)
type userPersistentStorageExample struct {
store map[string]UserPersistedValues
loadCalled int
saveCalled int
deleteCalled int
}
func (d *userPersistentStorageExample) Load(key string) (UserPersistedValues, bool) {
d.loadCalled++
val, ok := d.store[key]
return val, ok
}
func (d *userPersistentStorageExample) Save(key string, configName string, value StickyValues) {
d.saveCalled++
if _, ok := d.store[key]; !ok {
d.store[key] = make(UserPersistedValues)
}
d.store[key][configName] = value
}
func (d *userPersistentStorageExample) Delete(key string, configName string) {
d.deleteCalled++
delete(d.store[key], configName)
}
type brokenUserPersistentStorageExample struct{}
func (d *brokenUserPersistentStorageExample) Load(key string) (UserPersistedValues, bool) {
panic(errors.New("invalid Load function"))
}
func (d *brokenUserPersistentStorageExample) Save(key string, configName string, value StickyValues) {
panic(errors.New("invalid Save function"))
}
func (d *brokenUserPersistentStorageExample) Delete(key string, configName string) {
panic(errors.New("invalid Delete function"))
}