pin: add missing consts and convertion functions
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
May 15, 2016 at 18:15 UTC
c4195e532880156692f6bd8f6e65413f1aba3a33
1 file changed
+36
-1
pin/pin.go
+36
-1
@@ -22,8 +22,13 @@ var pinDatastoreKey = ds.NewKey("/local/pins")
22
var emptyKey = key.B58KeyDecode("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n")
23
24
const (
25
- linkDirect = "direct"
25
linkRecursive = "recursive"
26
+ linkDirect = "direct"
27
+ linkIndirect = "indirect"
28
+ linkInternal = "internal"
29
+ linkNotPinned = "not pinned"
30
+ linkAny = "any"
31
+ linkAll = "all"
32
)
33
34
type PinMode int
@@ -31,9 +36,39 @@ type PinMode int
36
const (
37
Recursive PinMode = iota
38
Direct
39
+ Indirect
40
+ Internal
41
NotPinned
42
+ Any
43
)
44
45
+func PinModeToString(mode PinMode) (string, bool) {
46
+ m := map[PinMode]string{
47
+ Recursive: linkRecursive,
48
+ Direct: linkDirect,
49
+ Indirect: linkIndirect,
50
+ Internal: linkInternal,
51
+ NotPinned: linkNotPinned,
52
+ Any: linkAny,
53
+ }
54
+ s, ok := m[mode]
55
+ return s, ok
56
+}
57
+
58
+func StringToPinMode(s string) (PinMode, bool) {
59
+ m := map[string]PinMode{
60
+ linkRecursive: Recursive,
61
+ linkDirect: Direct,
62
+ linkIndirect: Indirect,
63
+ linkInternal: Internal,
64
+ linkNotPinned: NotPinned,
65
+ linkAny: Any,
66
+ linkAll: Any, // "all" and "any" means the same thing
67
+ }
68
+ mode, ok := m[s]
69
+ return mode, ok
70
+}
71
+
72
type Pinner interface {
73
IsPinned(key.Key) (string, bool, error)
74
IsPinnedWithType(key.Key, string) (string, bool, error)