-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathwrapper.go
46 lines (35 loc) · 1.15 KB
/
wrapper.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
package store
import (
"context"
"fmt"
"github.com/ulule/gokvstores"
)
type kvstoreWrapper struct {
gokvstores.KVStore
Prefix string
}
func (k *kvstoreWrapper) prefixed(key string) string {
return fmt.Sprint(k.Prefix, key)
}
func (k *kvstoreWrapper) Set(ctx context.Context, key string, value interface{}) error {
return k.KVStore.Set(ctx, k.prefixed(key), value)
}
func (k *kvstoreWrapper) Get(ctx context.Context, key string) (interface{}, error) {
return k.KVStore.Get(ctx, k.prefixed(key))
}
func (k *kvstoreWrapper) Exists(ctx context.Context, keys ...string) (bool, error) {
newkeys := make([]string, len(keys))
for i := range keys {
newkeys[i] = k.prefixed(keys[i])
}
return k.KVStore.Exists(ctx, newkeys...)
}
func (k *kvstoreWrapper) AppendSlice(ctx context.Context, key string, values ...interface{}) error {
return k.KVStore.AppendSlice(ctx, k.prefixed(key), values...)
}
func (k *kvstoreWrapper) GetSlice(ctx context.Context, key string) ([]interface{}, error) {
return k.KVStore.GetSlice(ctx, k.prefixed(key))
}
func (k *kvstoreWrapper) Delete(ctx context.Context, key string) error {
return k.KVStore.Delete(ctx, k.prefixed(key))
}