-
Notifications
You must be signed in to change notification settings - Fork 8
/
statestore.go
43 lines (37 loc) · 1.01 KB
/
statestore.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
package bytengine
import (
"fmt"
"log"
)
var stsPlugins = make(map[string]StateStore)
// Manages authentication tokens, upload tickets and caching
type StateStore interface {
TokenSet(token, user string, timeout int64) error
TokenGet(token string) (string, error)
CacheSet(id, value string, timeout int64) error
CacheGet(id string) (string, error)
ClearAll() error
Start(config string) error
}
func RegisterStateStore(name string, plugin StateStore) {
if plugin == nil {
log.Fatal("State Store Plugin Registration: plugin is nil")
}
if _, exists := stsPlugins[name]; exists {
log.Printf("State Store Plugin Registration: plugin %q already registered", name)
return
}
stsPlugins[name] = plugin
}
func NewStateStore(pluginName, config string) (plugin StateStore, err error) {
plugin, ok := stsPlugins[pluginName]
if !ok {
err = fmt.Errorf("State Store Plugin Creation: unknown plugin name %q (forgot to import?)", pluginName)
return
}
err = plugin.Start(config)
if err != nil {
plugin = nil
}
return
}