forked from Unleash/unleash-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_storage.go
55 lines (43 loc) · 1.14 KB
/
bootstrap_storage.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
package unleash
import (
"encoding/json"
"fmt"
"io"
"github.com/Unleash/unleash-client-go/v4/api"
)
type BootstrapStorage struct {
backingStore DefaultStorage
Reader io.Reader
}
func (bs *BootstrapStorage) Load() error {
if len(bs.backingStore.data) > 0 || bs.Reader == nil {
return nil
}
dec := json.NewDecoder(bs.Reader)
clientFeatures := api.FeatureResponse{}
if err := dec.Decode(&clientFeatures); err != nil {
return err
}
bs.backingStore.data = clientFeatures.FeatureMap()
return nil
}
func (bs *BootstrapStorage) Init(backupPath string, appName string) {
bs.backingStore.Init(backupPath, appName)
err := bs.Load()
if err != nil {
fmt.Printf("Could not load bootstrap storage, because: %s", err.Error())
return
}
}
func (bs *BootstrapStorage) Reset(data map[string]interface{}, persist bool) error {
return bs.backingStore.Reset(data, persist)
}
func (bs *BootstrapStorage) Persist() error {
return bs.backingStore.Persist()
}
func (bs *BootstrapStorage) Get(key string) (interface{}, bool) {
return bs.backingStore.Get(key)
}
func (bs *BootstrapStorage) List() []interface{} {
return bs.backingStore.List()
}