This repository has been archived by the owner on Aug 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.go
71 lines (55 loc) · 1.37 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package kv
import (
"fmt"
"golang.org/x/net/context"
)
type wrapper struct {
Provider
}
func (w *wrapper) fillNode(ctx context.Context, n Node) (*Node, error) {
cur, err := w.Get(ctx, n.Key)
if err != nil {
return nil, err
}
if cur.IsDir {
var childs []Node
for _, child := range cur.Children {
if child, err := w.fillNode(ctx, child); err != nil {
return nil, err
} else {
childs = append(childs, *child)
}
}
cur.Children = childs
}
return cur, nil
}
func (w *wrapper) RGet(ctx context.Context, key string) (*Node, error) {
if v, ok := w.Provider.(RecursiveGetter); ok {
return v.RGet(ctx, key)
}
root, err := w.Get(ctx, key)
if err != nil {
return nil, err
}
// fall back to get
return w.fillNode(ctx, *root)
}
func (w *wrapper) Watch(ctx context.Context, key string) (*Node, error) {
if v, ok := w.Provider.(KeyWatcher); ok {
return v.Watch(ctx, key)
}
return nil, fmt.Errorf("Watch not supported by provider")
}
func (w *wrapper) Move(ctx context.Context, keyOld, keyNew string) error {
if v, ok := w.Provider.(Mover); ok {
return v.Move(ctx, keyOld, keyNew)
}
return fmt.Errorf("Move not supported by provider")
}
func (w *wrapper) Copy(ctx context.Context, keyOld, keyNew string) error {
if v, ok := w.Provider.(Copier); ok {
return v.Copy(ctx, keyOld, keyNew)
}
return fmt.Errorf("Copy not supported by provider")
}