@cryptotaxi247 / kubo / commits / c354e1962

coreapi: use defined functions for pin type option

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Mar 25, 2018 at 13:58 UTC c354e19628e82dae101a4110903ac1bc1c002185
2 files changed +33 -5
core/coreapi/interface/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
core/coreapi/pin_test.go
+3 -3
@@ -121,7 +121,7 @@ func TestPinRecursive(t *testing.T) {
121 t.Errorf("unexpected pin list len: %d", len(list))
122 }
123
124 - list, err = api.Pin().Ls(ctx, opt.Pin.Type("direct"))
124 + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Direct())
125 if err != nil {
126 t.Fatal(err)
127 }
@@ -134,7 +134,7 @@ func TestPinRecursive(t *testing.T) {
134 t.Error("unexpected path")
135 }
136
137 - list, err = api.Pin().Ls(ctx, opt.Pin.Type("recursive"))
137 + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive())
138 if err != nil {
139 t.Fatal(err)
140 }
@@ -147,7 +147,7 @@ func TestPinRecursive(t *testing.T) {
147 t.Error("unexpected path")
148 }
149
150 - list, err = api.Pin().Ls(ctx, opt.Pin.Type("indirect"))
150 + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect())
151 if err != nil {
152 t.Fatal(err)
153 }