-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
51 lines (43 loc) · 1.12 KB
/
driver.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
package main
import (
"time"
)
// StorageDriver is the storage driver interface
type StorageDriver interface {
watchForChanges(*FlagCache, uint64)
loadAllFlags(*FlagCache) (uint64, error)
saveFlag(*Flag) error
deleteFlag(string) error
}
// MemoryDriver is a container for memory driver config
type MemoryDriver struct {
fc *FlagCache
}
// NewMemoryDriver returns a StorageDriver interface'd object.
func NewMemoryDriver() (*MemoryDriver, error) {
driver := &MemoryDriver{}
return driver, nil
}
// Dummy watch loop
func (driver *MemoryDriver) watchForChanges(fc *FlagCache, version uint64) {
for true {
time.Sleep(3 * time.Second)
}
}
// No policies to load on start, since we don't have durable storage.
func (driver *MemoryDriver) loadAllFlags(fc *FlagCache) (uint64, error) {
driver.fc = fc
return 1, nil
}
// Update a flag in the in-mem cache
func (driver *MemoryDriver) saveFlag(f *Flag) error {
if err := driver.fc.Upsert(f); err != nil {
return err
}
return nil
}
// Delete a flag from the in-mem cache
func (driver *MemoryDriver) deleteFlag(flagName string) error {
driver.fc.Delete(flagName)
return nil
}