mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 07:28:20 +08:00
coreapi: use defined functions for pin type option
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -61,10 +61,38 @@ func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
|
||||
return options, nil
|
||||
}
|
||||
|
||||
type pinOpts struct{}
|
||||
type pinType struct{}
|
||||
|
||||
type pinOpts struct {
|
||||
Type pinType
|
||||
}
|
||||
|
||||
var Pin pinOpts
|
||||
|
||||
// All is an option for Pin.Ls which will make it return all pins. It is
|
||||
// the default
|
||||
func (_ pinType) All() PinLsOption {
|
||||
return Pin.pinType("all")
|
||||
}
|
||||
|
||||
// Recursive is an option for Pin.Ls which will make it only return recursive
|
||||
// pins
|
||||
func (_ pinType) Recursive() PinLsOption {
|
||||
return Pin.pinType("recursive")
|
||||
}
|
||||
|
||||
// Direct is an option for Pin.Ls which will make it only return direct (non
|
||||
// recursive) pins
|
||||
func (_ pinType) Direct() PinLsOption {
|
||||
return Pin.pinType("direct")
|
||||
}
|
||||
|
||||
// Indirect is an option for Pin.Ls which will make it only return indirect pins
|
||||
// (objects referenced by other recursively pinned objects)
|
||||
func (_ pinType) Indirect() PinLsOption {
|
||||
return Pin.pinType("indirect")
|
||||
}
|
||||
|
||||
// Recursive is an option for Pin.Add which specifies whether to pin an entire
|
||||
// object tree or just one object. Default: true
|
||||
func (_ pinOpts) Recursive(recucsive bool) PinAddOption {
|
||||
@ -83,7 +111,7 @@ func (_ pinOpts) Recursive(recucsive bool) PinAddOption {
|
||||
// * "indirect" - indirectly pinned objects (referenced by recursively pinned
|
||||
// objects)
|
||||
// * "all" - all pinned objects (default)
|
||||
func (_ pinOpts) Type(t string) PinLsOption {
|
||||
func (_ pinOpts) pinType(t string) PinLsOption {
|
||||
return func(settings *PinLsSettings) error {
|
||||
settings.Type = t
|
||||
return nil
|
||||
|
@ -121,7 +121,7 @@ func TestPinRecursive(t *testing.T) {
|
||||
t.Errorf("unexpected pin list len: %d", len(list))
|
||||
}
|
||||
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type("direct"))
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type.Direct())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -134,7 +134,7 @@ func TestPinRecursive(t *testing.T) {
|
||||
t.Error("unexpected path")
|
||||
}
|
||||
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type("recursive"))
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -147,7 +147,7 @@ func TestPinRecursive(t *testing.T) {
|
||||
t.Error("unexpected path")
|
||||
}
|
||||
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type("indirect"))
|
||||
list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user