-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathbootstrap_storage.go
More file actions
42 lines (34 loc) · 1016 Bytes
/
bootstrap_storage.go
File metadata and controls
42 lines (34 loc) · 1016 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
42
package unleash
import (
"encoding/json"
"io"
"github.com/Unleash/unleash-go-sdk/v6/api"
)
type BootstrapStorage struct {
backingStore DefaultStorage
Reader io.Reader
}
func (ds *BootstrapStorage) Init(backupPath, appName string) {
ds.backingStore.Init(backupPath, appName)
}
func (bs *BootstrapStorage) Load() (*api.FeatureResponse, error) {
if bs.Reader == nil {
return nil, nil
}
dec := json.NewDecoder(bs.Reader)
clientFeatures := api.FeatureResponse{}
if err := dec.Decode(&clientFeatures); err == nil {
return &clientFeatures, nil
}
// If we reach here, there was an error decoding the features from the reader
// So we fall back to loading from the decorated store. If that also fails
// it's not a major issue since the SDK will hydrate from the API
if data, err := bs.backingStore.Load(); err == nil {
return data, nil
} else {
return nil, err
}
}
func (bs *BootstrapStorage) Persist(features *api.FeatureResponse) error {
return bs.backingStore.Persist(features)
}