coreapi: use defined functions for pin type option
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@2e3f9758c88ce4572922c3fd4e8ef51c703e183d This commit was moved from ipfs/boxo@8a0f4029598ebf3be0d56e91fe07675702349a6d
Łukasz Magiera committed
Mar 25, 2018 at 13:58 UTC
8fea8513e3acbd23258c873a02808daf62ced490
1 file changed
+30
-2
core/coreiface/options/pin.go
+30
-2
@@ -61,10 +61,38 @@ func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
61
return options, nil
62
}
63
64
-type pinOpts struct{}
64
+type pinType struct{}
65
+
66
+type pinOpts struct {
67
+ Type pinType
68
+}
69
70
var Pin pinOpts
71
72
+// All is an option for Pin.Ls which will make it return all pins. It is
73
+// the default
74
+func (_ pinType) All() PinLsOption {
75
+ return Pin.pinType("all")
76
+}
77
+
78
+// Recursive is an option for Pin.Ls which will make it only return recursive
79
+// pins
80
+func (_ pinType) Recursive() PinLsOption {
81
+ return Pin.pinType("recursive")
82
+}
83
+
84
+// Direct is an option for Pin.Ls which will make it only return direct (non
85
+// recursive) pins
86
+func (_ pinType) Direct() PinLsOption {
87
+ return Pin.pinType("direct")
88
+}
89
+
90
+// Indirect is an option for Pin.Ls which will make it only return indirect pins
91
+// (objects referenced by other recursively pinned objects)
92
+func (_ pinType) Indirect() PinLsOption {
93
+ return Pin.pinType("indirect")
94
+}
95
+
96
// Recursive is an option for Pin.Add which specifies whether to pin an entire
97
// object tree or just one object. Default: true
98
func (_ pinOpts) Recursive(recucsive bool) PinAddOption {
@@ -83,7 +111,7 @@ func (_ pinOpts) Recursive(recucsive bool) PinAddOption {
111
// * "indirect" - indirectly pinned objects (referenced by recursively pinned
112
// objects)
113
// * "all" - all pinned objects (default)
86
-func (_ pinOpts) Type(t string) PinLsOption {
114
+func (_ pinOpts) pinType(t string) PinLsOption {
115
return func(settings *PinLsSettings) error {
116
settings.Type = t
117
return nil