@cryptotaxi247 / kubo / commits / 79f56c183

coreapi: remove options from interfaces

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

Łukasz Magiera committed Mar 11, 2018 at 18:55 UTC 79f56c1831a854f298363e2f84fe9084f61f016c
25 files changed +160 -206
core/coreapi/block.go
+1 -4
@@ -17,10 +17,7 @@ import (
17 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
18 )
19
20 -type BlockAPI struct {
21 - *CoreAPI
22 - *caopts.BlockOptions
23 -}
20 +type BlockAPI CoreAPI
21
22 type BlockStat struct {
23 path coreiface.Path
core/coreapi/block_test.go
+6 -4
@@ -6,6 +6,8 @@ import (
6 "strings"
7 "testing"
8
9 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
10 +
11 mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
12 )
13
@@ -33,7 +35,7 @@ func TestBlockPutFormat(t *testing.T) {
35 t.Error(err)
36 }
37
36 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithFormat("cbor"))
38 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("cbor"))
39 if err != nil {
40 t.Error(err)
41 }
@@ -50,7 +52,7 @@ func TestBlockPutHash(t *testing.T) {
52 t.Error(err)
53 }
54
53 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithHash(mh.KECCAK_512, -1))
55 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
56 if err != nil {
57 t.Error(err)
58 }
@@ -67,7 +69,7 @@ func TestBlockGet(t *testing.T) {
69 t.Error(err)
70 }
71
70 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithHash(mh.KECCAK_512, -1))
72 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
73 if err != nil {
74 t.Error(err)
75 }
@@ -134,7 +136,7 @@ func TestBlockRm(t *testing.T) {
136 t.Errorf("unexpected error; %s", err.Error())
137 }
138
137 - err = api.Block().Rm(ctx, res, api.Block().WithForce(true))
139 + err = api.Block().Rm(ctx, res, opt.Block.Force(true))
140 if err != nil {
141 t.Error(err)
142 }
core/coreapi/coreapi.go
+6 -6
@@ -31,32 +31,32 @@ func (api *CoreAPI) Unixfs() coreiface.UnixfsAPI {
31
32 // Block returns the BlockAPI interface implementation backed by the go-ipfs node
33 func (api *CoreAPI) Block() coreiface.BlockAPI {
34 - return &BlockAPI{api, nil}
34 + return (*BlockAPI)(api)
35 }
36
37 // Dag returns the DagAPI interface implementation backed by the go-ipfs node
38 func (api *CoreAPI) Dag() coreiface.DagAPI {
39 - return &DagAPI{api, nil}
39 + return (*DagAPI)(api)
40 }
41
42 // Name returns the NameAPI interface implementation backed by the go-ipfs node
43 func (api *CoreAPI) Name() coreiface.NameAPI {
44 - return &NameAPI{api, nil}
44 + return (*NameAPI)(api)
45 }
46
47 // Key returns the KeyAPI interface implementation backed by the go-ipfs node
48 func (api *CoreAPI) Key() coreiface.KeyAPI {
49 - return &KeyAPI{api, nil}
49 + return (*KeyAPI)(api)
50 }
51
52 //Object returns the ObjectAPI interface implementation backed by the go-ipfs node
53 func (api *CoreAPI) Object() coreiface.ObjectAPI {
54 - return &ObjectAPI{api, nil}
54 + return (*ObjectAPI)(api)
55 }
56
57 // Pin returns the PinAPI interface implementation backed by the go-ipfs node
58 func (api *CoreAPI) Pin() coreiface.PinAPI {
59 - return &PinAPI{api, nil}
59 + return (*PinAPI)(api)
60 }
61
62 // ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the
core/coreapi/dag.go
+2 -5
@@ -15,10 +15,7 @@ import (
15 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
16 )
17
18 -type DagAPI struct {
19 - *CoreAPI
20 - *caopts.DagOptions
21 -}
18 +type DagAPI CoreAPI
19
20 // Put inserts data using specified format and input encoding. Unless used with
21 // `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
@@ -79,5 +76,5 @@ func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.Da
76 }
77
78 func (api *DagAPI) core() coreiface.CoreAPI {
82 - return api.CoreAPI
79 + return (*CoreAPI)(api)
80 }
core/coreapi/dag_test.go
+3 -1
@@ -9,6 +9,8 @@ import (
9 coreapi "github.com/ipfs/go-ipfs/core/coreapi"
10
11 mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
12 +
13 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
14 )
15
16 var (
@@ -45,7 +47,7 @@ func TestPutWithHash(t *testing.T) {
47 t.Error(err)
48 }
49
48 - res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`), api.Dag().WithHash(mh.ID, -1))
50 + res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`), opt.Dag.Hash(mh.ID, -1))
51 if err != nil {
52 t.Error(err)
53 }
core/coreapi/interface/block.go
-13
@@ -21,15 +21,6 @@ type BlockAPI interface {
21 // Put imports raw block data, hashing it using specified settings.
22 Put(context.Context, io.Reader, ...options.BlockPutOption) (Path, error)
23
24 - // WithFormat is an option for Put which specifies the multicodec to use to
25 - // serialize the object. Default is "v0"
26 - WithFormat(codec string) options.BlockPutOption
27 -
28 - // WithHash is an option for Put which specifies the multihash settings to use
29 - // when hashing the object. Default is mh.SHA2_256 (0x12).
30 - // If mhLen is set to -1, default length for the hash will be used
31 - WithHash(mhType uint64, mhLen int) options.BlockPutOption
32 -
24 // Get attempts to resolve the path and return a reader for data in the block
25 Get(context.Context, Path) (io.Reader, error)
26
@@ -40,10 +31,6 @@ type BlockAPI interface {
31 // will be returned
32 Rm(context.Context, Path, ...options.BlockRmOption) error
33
43 - // WithForce is an option for Rm which, when set to true, will ignore
44 - // non-existing blocks
45 - WithForce(force bool) options.BlockRmOption
46 -
34 // Stat returns information on
35 Stat(context.Context, Path) (BlockStat, error)
36 }
core/coreapi/interface/dag.go
-18
@@ -16,27 +16,9 @@ type DagAPI interface {
16 // "sha256" are used.
17 Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error)
18
19 - // WithInputEnc is an option for Put which specifies the input encoding of the
20 - // data. Default is "json", most formats/codecs support "raw"
21 - WithInputEnc(enc string) options.DagPutOption
22 -
23 - // WithCodec is an option for Put which specifies the multicodec to use to
24 - // serialize the object. Default is cid.DagCBOR (0x71)
25 - WithCodec(codec uint64) options.DagPutOption
26 -
27 - // WithHash is an option for Put which specifies the multihash settings to use
28 - // when hashing the object. Default is based on the codec used
29 - // (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for
30 - // the hash will be used
31 - WithHash(mhType uint64, mhLen int) options.DagPutOption
32 -
19 // Get attempts to resolve and get the node specified by the path
20 Get(ctx context.Context, path Path) (ipld.Node, error)
21
22 // Tree returns list of paths within a node specified by the path.
23 Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
38 -
39 - // WithDepth is an option for Tree which specifies maximum depth of the
40 - // returned tree. Default is -1 (no depth limit)
41 - WithDepth(depth int) options.DagTreeOption
24 }
core/coreapi/interface/key.go
-19
@@ -20,29 +20,10 @@ type KeyAPI interface {
20 // name and returns a base58 encoded multihash of it's public key
21 Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)
22
23 - // WithType is an option for Generate which specifies which algorithm
24 - // should be used for the key. Default is options.RSAKey
25 - //
26 - // Supported key types:
27 - // * options.RSAKey
28 - // * options.Ed25519Key
29 - WithType(algorithm string) options.KeyGenerateOption
30 -
31 - // WithSize is an option for Generate which specifies the size of the key to
32 - // generated. Default is -1
33 - //
34 - // value of -1 means 'use default size for key type':
35 - // * 2048 for RSA
36 - WithSize(size int) options.KeyGenerateOption
37 -
23 // Rename renames oldName key to newName. Returns the key and whether another
24 // key was overwritten, or an error
25 Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)
26
42 - // WithForce is an option for Rename which specifies whether to allow to
43 - // replace existing keys.
44 - WithForce(force bool) options.KeyRenameOption
45 -
27 // List lists keys stored in keystore
28 List(ctx context.Context) ([]Key, error)
29
core/coreapi/interface/name.go
-24
@@ -2,7 +2,6 @@ package iface
2
3 import (
4 "context"
5 - "time"
5
6 options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
7 )
@@ -27,29 +26,6 @@ type NameAPI interface {
26 // Publish announces new IPNS name
27 Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)
28
30 - // WithValidTime is an option for Publish which specifies for how long the
31 - // entry will remain valid. Default value is 24h
32 - WithValidTime(validTime time.Duration) options.NamePublishOption
33 -
34 - // WithKey is an option for Publish which specifies the key to use for
35 - // publishing. Default value is "self" which is the node's own PeerID.
36 - // The key parameter must be either PeerID or keystore key alias.
37 - //
38 - // You can use KeyAPI to list and generate more names and their respective keys.
39 - WithKey(key string) options.NamePublishOption
40 -
29 // Resolve attempts to resolve the newest version of the specified name
30 Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
43 -
44 - // WithRecursive is an option for Resolve which specifies whether to perform a
45 - // recursive lookup. Default value is false
46 - WithRecursive(recursive bool) options.NameResolveOption
47 -
48 - // WithLocal is an option for Resolve which specifies if the lookup should be
49 - // offline. Default value is false
50 - WithLocal(local bool) options.NameResolveOption
51 -
52 - // WithCache is an option for Resolve which specifies if cache should be used.
53 - // Default value is true
54 - WithCache(cache bool) options.NameResolveOption
31 }
core/coreapi/interface/object.go
-28
@@ -37,33 +37,9 @@ type ObjectAPI interface {
37 // New creates new, empty (by default) dag-node.
38 New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
39
40 - // WithType is an option for New which allows to change the type of created
41 - // dag node.
42 - //
43 - // Supported types:
44 - // * 'empty' - Empty node
45 - // * 'unixfs-dir' - Empty UnixFS directory
46 - WithType(string) options.ObjectNewOption
47 -
40 // Put imports the data into merkledag
41 Put(context.Context, io.Reader, ...options.ObjectPutOption) (Path, error)
42
51 - // WithInputEnc is an option for Put which specifies the input encoding of the
52 - // data. Default is "json".
53 - //
54 - // Supported encodings:
55 - // * "protobuf"
56 - // * "json"
57 - WithInputEnc(e string) options.ObjectPutOption
58 -
59 - // WithDataType specifies the encoding of data field when using Josn or XML
60 - // input encoding.
61 - //
62 - // Supported types:
63 - // * "text" (default)
64 - // * "base64"
65 - WithDataType(t string) options.ObjectPutOption
66 -
43 // Get returns the node for the path
44 Get(context.Context, Path) (ipld.Node, error)
45
@@ -81,10 +57,6 @@ type ObjectAPI interface {
57 // with WithCreate option).
58 AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error)
59
84 - // WithCreate is an option for AddLink which specifies whether create required
85 - // directories for the child
86 - WithCreate(create bool) options.ObjectAddLinkOption
87 -
60 // RmLink removes a link from the node
61 RmLink(ctx context.Context, base Path, link string) (Path, error)
62
core/coreapi/interface/options/block.go
+13 -4
@@ -47,16 +47,23 @@ func BlockRmOptions(opts ...BlockRmOption) (*BlockRmSettings, error) {
47 return options, nil
48 }
49
50 -type BlockOptions struct{}
50 +type blockOpts struct{}
51
52 -func (api *BlockOptions) WithFormat(codec string) BlockPutOption {
52 +var Block blockOpts
53 +
54 +// Format is an option for Block.Put which specifies the multicodec to use to
55 +// serialize the object. Default is "v0"
56 +func (_ blockOpts) Format(codec string) BlockPutOption {
57 return func(settings *BlockPutSettings) error {
58 settings.Codec = codec
59 return nil
60 }
61 }
62
59 -func (api *BlockOptions) WithHash(mhType uint64, mhLen int) BlockPutOption {
63 +// Hash is an option for Block.Put which specifies the multihash settings to use
64 +// when hashing the object. Default is mh.SHA2_256 (0x12).
65 +// If mhLen is set to -1, default length for the hash will be used
66 +func (_ blockOpts) Hash(mhType uint64, mhLen int) BlockPutOption {
67 return func(settings *BlockPutSettings) error {
68 settings.MhType = mhType
69 settings.MhLength = mhLen
@@ -64,7 +71,9 @@ func (api *BlockOptions) WithHash(mhType uint64, mhLen int) BlockPutOption {
71 }
72 }
73
67 -func (api *BlockOptions) WithForce(force bool) BlockRmOption {
74 +// Force is an option for Block.Rm which, when set to true, will ignore
75 +// non-existing blocks
76 +func (_ blockOpts) Force(force bool) BlockRmOption {
77 return func(settings *BlockRmSettings) error {
78 settings.Force = force
79 return nil
core/coreapi/interface/options/dag.go
+17 -5
@@ -51,23 +51,33 @@ func DagTreeOptions(opts ...DagTreeOption) (*DagTreeSettings, error) {
51 return options, nil
52 }
53
54 -type DagOptions struct{}
54 +type dagOpts struct{}
55
56 -func (api *DagOptions) WithInputEnc(enc string) DagPutOption {
56 +var Dag dagOpts
57 +
58 +// InputEnc is an option for Dag.Put which specifies the input encoding of the
59 +// data. Default is "json", most formats/codecs support "raw"
60 +func (_ dagOpts) InputEnc(enc string) DagPutOption {
61 return func(settings *DagPutSettings) error {
62 settings.InputEnc = enc
63 return nil
64 }
65 }
66
63 -func (api *DagOptions) WithCodec(codec uint64) DagPutOption {
67 +// Codec is an option for Dag.Put which specifies the multicodec to use to
68 +// serialize the object. Default is cid.DagCBOR (0x71)
69 +func (_ dagOpts) Codec(codec uint64) DagPutOption {
70 return func(settings *DagPutSettings) error {
71 settings.Codec = codec
72 return nil
73 }
74 }
75
70 -func (api *DagOptions) WithHash(mhType uint64, mhLen int) DagPutOption {
76 +// Hash is an option for Dag.Put which specifies the multihash settings to use
77 +// when hashing the object. Default is based on the codec used
78 +// (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for
79 +// the hash will be used
80 +func (_ dagOpts) Hash(mhType uint64, mhLen int) DagPutOption {
81 return func(settings *DagPutSettings) error {
82 settings.MhType = mhType
83 settings.MhLength = mhLen
@@ -75,7 +85,9 @@ func (api *DagOptions) WithHash(mhType uint64, mhLen int) DagPutOption {
85 }
86 }
87
78 -func (api *DagOptions) WithDepth(depth int) DagTreeOption {
88 +// Depth is an option for Dag.Tree which specifies maximum depth of the
89 +// returned tree. Default is -1 (no depth limit)
90 +func (_ dagOpts) Depth(depth int) DagTreeOption {
91 return func(settings *DagTreeSettings) error {
92 settings.Depth = depth
93 return nil
core/coreapi/interface/options/key.go
+19 -4
@@ -48,23 +48,38 @@ func KeyRenameOptions(opts ...KeyRenameOption) (*KeyRenameSettings, error) {
48 return options, nil
49 }
50
51 -type KeyOptions struct{}
51 +type keyOpts struct{}
52
53 -func (api *KeyOptions) WithType(algorithm string) KeyGenerateOption {
53 +var Key keyOpts
54 +
55 +// Type is an option for Key.Generate which specifies which algorithm
56 +// should be used for the key. Default is options.RSAKey
57 +//
58 +// Supported key types:
59 +// * options.RSAKey
60 +// * options.Ed25519Key
61 +func (_ keyOpts) Type(algorithm string) KeyGenerateOption {
62 return func(settings *KeyGenerateSettings) error {
63 settings.Algorithm = algorithm
64 return nil
65 }
66 }
67
60 -func (api *KeyOptions) WithSize(size int) KeyGenerateOption {
68 +// Size is an option for Key.Generate which specifies the size of the key to
69 +// generated. Default is -1
70 +//
71 +// value of -1 means 'use default size for key type':
72 +// * 2048 for RSA
73 +func (_ keyOpts) Size(size int) KeyGenerateOption {
74 return func(settings *KeyGenerateSettings) error {
75 settings.Size = size
76 return nil
77 }
78 }
79
67 -func (api *KeyOptions) WithForce(force bool) KeyRenameOption {
80 +// Force is an option for Key.Rename which specifies whether to allow to
81 +// replace existing keys.
82 +func (_ keyOpts) Force(force bool) KeyRenameOption {
83 return func(settings *KeyRenameSettings) error {
84 settings.Force = force
85 return nil
core/coreapi/interface/options/name.go
+21 -6
@@ -55,37 +55,52 @@ func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error)
55 return options, nil
56 }
57
58 -type NameOptions struct{}
58 +type nameOpts struct{}
59
60 -func (api *NameOptions) WithValidTime(validTime time.Duration) NamePublishOption {
60 +var Name nameOpts
61 +
62 +// ValidTime is an option for Name.Publish which specifies for how long the
63 +// entry will remain valid. Default value is 24h
64 +func (_ nameOpts) ValidTime(validTime time.Duration) NamePublishOption {
65 return func(settings *NamePublishSettings) error {
66 settings.ValidTime = validTime
67 return nil
68 }
69 }
70
67 -func (api *NameOptions) WithKey(key string) NamePublishOption {
71 +// Key is an option for Name.Publish which specifies the key to use for
72 +// publishing. Default value is "self" which is the node's own PeerID.
73 +// The key parameter must be either PeerID or keystore key alias.
74 +//
75 +// You can use KeyAPI to list and generate more names and their respective keys.
76 +func (_ nameOpts) Key(key string) NamePublishOption {
77 return func(settings *NamePublishSettings) error {
78 settings.Key = key
79 return nil
80 }
81 }
82
74 -func (api *NameOptions) WithRecursive(recursive bool) NameResolveOption {
83 +// Recursive is an option for Name.Resolve which specifies whether to perform a
84 +// recursive lookup. Default value is false
85 +func (_ nameOpts) Recursive(recursive bool) NameResolveOption {
86 return func(settings *NameResolveSettings) error {
87 settings.Recursive = recursive
88 return nil
89 }
90 }
91
81 -func (api *NameOptions) WithLocal(local bool) NameResolveOption {
92 +// Local is an option for Name.Resolve which specifies if the lookup should be
93 +// offline. Default value is false
94 +func (_ nameOpts) Local(local bool) NameResolveOption {
95 return func(settings *NameResolveSettings) error {
96 settings.Local = local
97 return nil
98 }
99 }
100
88 -func (api *NameOptions) WithCache(cache bool) NameResolveOption {
101 +// Cache is an option for Name.Resolve which specifies if cache should be used.
102 +// Default value is true
103 +func (_ nameOpts) Cache(cache bool) NameResolveOption {
104 return func(settings *NameResolveSettings) error {
105 settings.Cache = cache
106 return nil
core/coreapi/interface/options/object.go
+27 -5
@@ -60,30 +60,52 @@ func ObjectAddLinkOptions(opts ...ObjectAddLinkOption) (*ObjectAddLinkSettings,
60 return options, nil
61 }
62
63 -type ObjectOptions struct{}
63 +type objectOpts struct{}
64
65 -func (api *ObjectOptions) WithType(t string) ObjectNewOption {
65 +var Object objectOpts
66 +
67 +// Type is an option for Object.New which allows to change the type of created
68 +// dag node.
69 +//
70 +// Supported types:
71 +// * 'empty' - Empty node
72 +// * 'unixfs-dir' - Empty UnixFS directory
73 +func (_ objectOpts) Type(t string) ObjectNewOption {
74 return func(settings *ObjectNewSettings) error {
75 settings.Type = t
76 return nil
77 }
78 }
79
72 -func (api *ObjectOptions) WithInputEnc(e string) ObjectPutOption {
80 +// InputEnc is an option for Object.Put which specifies the input encoding of the
81 +// data. Default is "json".
82 +//
83 +// Supported encodings:
84 +// * "protobuf"
85 +// * "json"
86 +func (_ objectOpts) InputEnc(e string) ObjectPutOption {
87 return func(settings *ObjectPutSettings) error {
88 settings.InputEnc = e
89 return nil
90 }
91 }
92
79 -func (api *ObjectOptions) WithDataType(t string) ObjectPutOption {
93 +// DataType is an option for Object.Put which specifies the encoding of data
94 +// field when using Json or XML input encoding.
95 +//
96 +// Supported types:
97 +// * "text" (default)
98 +// * "base64"
99 +func (_ objectOpts) DataType(t string) ObjectPutOption {
100 return func(settings *ObjectPutSettings) error {
101 settings.DataType = t
102 return nil
103 }
104 }
105
86 -func (api *ObjectOptions) WithCreate(create bool) ObjectAddLinkOption {
106 +// Create is an option for Object.AddLink which specifies whether create required
107 +// directories for the child
108 +func (_ objectOpts) Create(create bool) ObjectAddLinkOption {
109 return func(settings *ObjectAddLinkSettings) error {
110 settings.Create = create
111 return nil
core/coreapi/interface/options/pin.go
+19 -4
@@ -61,23 +61,38 @@ func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
61 return options, nil
62 }
63
64 -type PinOptions struct{}
64 +type pinOpts struct{}
65
66 -func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption {
66 +var Pin pinOpts
67 +
68 +// Recursive is an option for Pin.Add which specifies whether to pin an entire
69 +// object tree or just one object. Default: true
70 +func (_ pinOpts) Recursive(recucsive bool) PinAddOption {
71 return func(settings *PinAddSettings) error {
72 settings.Recursive = recucsive
73 return nil
74 }
75 }
76
73 -func (api *PinOptions) WithType(t string) PinLsOption {
77 +// Type is an option for Pin.Ls which allows to specify which pin types should
78 +// be returned
79 +//
80 +// Supported values:
81 +// * "direct" - directly pinned objects
82 +// * "recursive" - roots of recursive pins
83 +// * "indirect" - indirectly pinned objects (referenced by recursively pinned
84 +// objects)
85 +// * "all" - all pinned objects (default)
86 +func (_ pinOpts) Type(t string) PinLsOption {
87 return func(settings *PinLsSettings) error {
88 settings.Type = t
89 return nil
90 }
91 }
92
80 -func (api *PinOptions) WithUnpin(unpin bool) PinUpdateOption {
93 +// Unpin is an option for Pin.Update which specifies whether to remove the old pin.
94 +// Default is true.
95 +func (_ pinOpts) Unpin(unpin bool) PinUpdateOption {
96 return func(settings *PinUpdateSettings) error {
97 settings.Unpin = unpin
98 return nil
core/coreapi/interface/pin.go
-15
@@ -39,24 +39,9 @@ type PinAPI interface {
39 // tree
40 Add(context.Context, Path, ...options.PinAddOption) error
41
42 - // WithRecursive is an option for Add which specifies whether to pin an entire
43 - // object tree or just one object. Default: true
44 - WithRecursive(bool) options.PinAddOption
45 -
42 // Ls returns list of pinned objects on this node
43 Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
44
49 - // WithType is an option for Ls which allows to specify which pin types should
50 - // be returned
51 - //
52 - // Supported values:
53 - // * "direct" - directly pinned objects
54 - // * "recursive" - roots of recursive pins
55 - // * "indirect" - indirectly pinned objects (referenced by recursively pinned
56 - // objects)
57 - // * "all" - all pinned objects (default)
58 - WithType(string) options.PinLsOption
59 -
45 // Rm removes pin for object specified by the path
46 Rm(context.Context, Path) error
47
core/coreapi/key.go
+1 -8
@@ -14,10 +14,7 @@ import (
14 crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
15 )
16
17 -type KeyAPI struct {
18 - *CoreAPI
19 - *caopts.KeyOptions
20 -}
17 +type KeyAPI CoreAPI
18
19 type key struct {
20 name string
@@ -203,7 +200,3 @@ func (api *KeyAPI) Remove(ctx context.Context, name string) (coreiface.Path, err
200
201 return (&key{"", pid.Pretty()}).Path(), nil
202 }
206 -
207 -func (api *KeyAPI) core() coreiface.CoreAPI {
208 - return api.CoreAPI
209 -}
core/coreapi/key_test.go
+6 -6
@@ -5,7 +5,7 @@ import (
5 "strings"
6 "testing"
7
8 - opts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9 )
10
11 func TestListSelf(t *testing.T) {
@@ -53,7 +53,7 @@ func TestRenameSelf(t *testing.T) {
53 }
54 }
55
56 - _, _, err = api.Key().Rename(ctx, "self", "foo", api.Key().WithForce(true))
56 + _, _, err = api.Key().Rename(ctx, "self", "foo", opt.Key.Force(true))
57 if err == nil {
58 t.Error("expected error to not be nil")
59 } else {
@@ -110,7 +110,7 @@ func TestGenerateSize(t *testing.T) {
110 t.Error(err)
111 }
112
113 - k, err := api.Key().Generate(ctx, "foo", api.Key().WithSize(1024))
113 + k, err := api.Key().Generate(ctx, "foo", opt.Key.Size(1024))
114 if err != nil {
115 t.Fatal(err)
116 return
@@ -132,7 +132,7 @@ func TestGenerateType(t *testing.T) {
132 t.Error(err)
133 }
134
135 - k, err := api.Key().Generate(ctx, "bar", api.Key().WithType(opts.Ed25519Key))
135 + k, err := api.Key().Generate(ctx, "bar", opt.Key.Type(opt.Ed25519Key))
136 if err != nil {
137 t.Fatal(err)
138 return
@@ -288,7 +288,7 @@ func TestRenameToSelfForce(t *testing.T) {
288 return
289 }
290
291 - _, _, err = api.Key().Rename(ctx, "foo", "self", api.Key().WithForce(true))
291 + _, _, err = api.Key().Rename(ctx, "foo", "self", opt.Key.Force(true))
292 if err == nil {
293 t.Error("expected error to not be nil")
294 } else {
@@ -346,7 +346,7 @@ func TestRenameOverwrite(t *testing.T) {
346 return
347 }
348
349 - k, overwrote, err := api.Key().Rename(ctx, "foo", "bar", api.Key().WithForce(true))
349 + k, overwrote, err := api.Key().Rename(ctx, "foo", "bar", opt.Key.Force(true))
350 if err != nil {
351 t.Fatal(err)
352 return
core/coreapi/name.go
+1 -8
@@ -20,10 +20,7 @@ import (
20 crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
21 )
22
23 -type NameAPI struct {
24 - *CoreAPI
25 - *caopts.NameOptions
26 -}
23 +type NameAPI CoreAPI
24
25 type ipnsEntry struct {
26 name string
@@ -135,10 +132,6 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
132 return &path{path: output}, nil
133 }
134
138 -func (api *NameAPI) core() coreiface.CoreAPI {
139 - return api.CoreAPI
140 -}
141 -
135 func keylookup(n *core.IpfsNode, k string) (crypto.PrivKey, error) {
136 res, err := n.GetKey(k)
137 if res != nil {
core/coreapi/name_test.go
+3 -2
@@ -10,6 +10,7 @@ import (
10 ipath "github.com/ipfs/go-ipfs/path"
11
12 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
14 )
15
16 var rnd = rand.New(rand.NewSource(0x62796532303137))
@@ -77,7 +78,7 @@ func TestBasicPublishResolveKey(t *testing.T) {
78 return
79 }
80
80 - e, err := api.Name().Publish(ctx, p, api.Name().WithKey(k.Name()))
81 + e, err := api.Name().Publish(ctx, p, opt.Name.Key(k.Name()))
82 if err != nil {
83 t.Fatal(err)
84 return
@@ -118,7 +119,7 @@ func TestBasicPublishResolveTimeout(t *testing.T) {
119 return
120 }
121
121 - e, err := api.Name().Publish(ctx, p, api.Name().WithValidTime(time.Millisecond*100))
122 + e, err := api.Name().Publish(ctx, p, opt.Name.ValidTime(time.Millisecond*100))
123 if err != nil {
124 t.Fatal(err)
125 return
core/coreapi/object.go
+2 -5
@@ -23,10 +23,7 @@ import (
23
24 const inputLimit = 2 << 20
25
26 -type ObjectAPI struct {
27 - *CoreAPI
28 - *caopts.ObjectOptions
29 -}
26 +type ObjectAPI CoreAPI
27
28 type Link struct {
29 Name, Hash string
@@ -288,7 +285,7 @@ func (api *ObjectAPI) patchData(ctx context.Context, path coreiface.Path, r io.R
285 }
286
287 func (api *ObjectAPI) core() coreiface.CoreAPI {
291 - return api.CoreAPI
288 + return (*CoreAPI)(api)
289 }
290
291 func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error) {
core/coreapi/object_test.go
+6 -4
@@ -7,6 +7,8 @@ import (
7 "io/ioutil"
8 "strings"
9 "testing"
10 +
11 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
12 )
13
14 func TestNew(t *testing.T) {
@@ -21,7 +23,7 @@ func TestNew(t *testing.T) {
23 t.Fatal(err)
24 }
25
24 - dirNode, err := api.Object().New(ctx, api.Object().WithType("unixfs-dir"))
26 + dirNode, err := api.Object().New(ctx, opt.Object.Type("unixfs-dir"))
27 if err != nil {
28 t.Fatal(err)
29 }
@@ -47,7 +49,7 @@ func TestObjectPut(t *testing.T) {
49 t.Fatal(err)
50 }
51
50 - p2, err := api.Object().Put(ctx, strings.NewReader(`{"Data":"YmFy"}`), api.Object().WithDataType("base64")) //bar
52 + p2, err := api.Object().Put(ctx, strings.NewReader(`{"Data":"YmFy"}`), opt.Object.DataType("base64")) //bar
53 if err != nil {
54 t.Fatal(err)
55 }
@@ -57,7 +59,7 @@ func TestObjectPut(t *testing.T) {
59 t.Fatal(err)
60 }
61
60 - p3, err := api.Object().Put(ctx, bytes.NewReader(pbBytes), api.Object().WithInputEnc("protobuf"))
62 + p3, err := api.Object().Put(ctx, bytes.NewReader(pbBytes), opt.Object.InputEnc("protobuf"))
63 if err != nil {
64 t.Fatal(err)
65 }
@@ -271,7 +273,7 @@ func TestObjectAddLinkCreate(t *testing.T) {
273 t.Fatalf("unexpected error: %s", err.Error())
274 }
275
274 - p3, err = api.Object().AddLink(ctx, p2, "abc/d", p2, api.Object().WithCreate(true))
276 + p3, err = api.Object().AddLink(ctx, p2, "abc/d", p2, opt.Object.Create(true))
277 if err != nil {
278 t.Fatal(err)
279 }
core/coreapi/pin.go
+1 -4
@@ -16,10 +16,7 @@ import (
16 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
17 )
18
19 -type PinAPI struct {
20 - *CoreAPI
21 - *caopts.PinOptions
22 -}
19 +type PinAPI CoreAPI
20
21 func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.PinAddOption) error {
22 settings, err := caopts.PinAddOptions(opts...)
core/coreapi/pin_test.go
+6 -4
@@ -4,6 +4,8 @@ import (
4 "context"
5 "strings"
6 "testing"
7 +
8 + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9 )
10
11 func TestPinAdd(t *testing.T) {
@@ -105,7 +107,7 @@ func TestPinRecursive(t *testing.T) {
107 t.Error(err)
108 }
109
108 - err = api.Pin().Add(ctx, p3, api.Pin().WithRecursive(false))
110 + err = api.Pin().Add(ctx, p3, opt.Pin.Recursive(false))
111 if err != nil {
112 t.Error(err)
113 }
@@ -119,7 +121,7 @@ func TestPinRecursive(t *testing.T) {
121 t.Errorf("unexpected pin list len: %d", len(list))
122 }
123
122 - list, err = api.Pin().Ls(ctx, api.Pin().WithType("direct"))
124 + list, err = api.Pin().Ls(ctx, opt.Pin.Type("direct"))
125 if err != nil {
126 t.Fatal(err)
127 }
@@ -132,7 +134,7 @@ func TestPinRecursive(t *testing.T) {
134 t.Error("unexpected path")
135 }
136
135 - list, err = api.Pin().Ls(ctx, api.Pin().WithType("recursive"))
137 + list, err = api.Pin().Ls(ctx, opt.Pin.Type("recursive"))
138 if err != nil {
139 t.Fatal(err)
140 }
@@ -145,7 +147,7 @@ func TestPinRecursive(t *testing.T) {
147 t.Error("unexpected path")
148 }
149
148 - list, err = api.Pin().Ls(ctx, api.Pin().WithType("indirect"))
150 + list, err = api.Pin().Ls(ctx, opt.Pin.Type("indirect"))
151 if err != nil {
152 t.Fatal(err)
153 }