diff --git a/core/coreapi/block.go b/core/coreapi/block.go index 176d562c2bf..a3f93230947 100644 --- a/core/coreapi/block.go +++ b/core/coreapi/block.go @@ -17,10 +17,7 @@ import ( blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format" ) -type BlockAPI struct { - *CoreAPI - *caopts.BlockOptions -} +type BlockAPI CoreAPI type BlockStat struct { path coreiface.Path diff --git a/core/coreapi/block_test.go b/core/coreapi/block_test.go index 7fcdbca7ea8..a7d1cb65650 100644 --- a/core/coreapi/block_test.go +++ b/core/coreapi/block_test.go @@ -6,6 +6,8 @@ import ( "strings" "testing" + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" + mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash" ) @@ -33,7 +35,7 @@ func TestBlockPutFormat(t *testing.T) { t.Error(err) } - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithFormat("cbor")) + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("cbor")) if err != nil { t.Error(err) } @@ -50,7 +52,7 @@ func TestBlockPutHash(t *testing.T) { t.Error(err) } - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithHash(mh.KECCAK_512, -1)) + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1)) if err != nil { t.Error(err) } @@ -67,7 +69,7 @@ func TestBlockGet(t *testing.T) { t.Error(err) } - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), api.Block().WithHash(mh.KECCAK_512, -1)) + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1)) if err != nil { t.Error(err) } @@ -134,7 +136,7 @@ func TestBlockRm(t *testing.T) { t.Errorf("unexpected error; %s", err.Error()) } - err = api.Block().Rm(ctx, res, api.Block().WithForce(true)) + err = api.Block().Rm(ctx, res, opt.Block.Force(true)) if err != nil { t.Error(err) } diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 01b42feb2d8..77c5b51ff16 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -31,32 +31,32 @@ func (api *CoreAPI) Unixfs() coreiface.UnixfsAPI { // Block returns the BlockAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Block() coreiface.BlockAPI { - return &BlockAPI{api, nil} + return (*BlockAPI)(api) } // Dag returns the DagAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Dag() coreiface.DagAPI { - return &DagAPI{api, nil} + return (*DagAPI)(api) } // Name returns the NameAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Name() coreiface.NameAPI { - return &NameAPI{api, nil} + return (*NameAPI)(api) } // Key returns the KeyAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Key() coreiface.KeyAPI { - return &KeyAPI{api, nil} + return (*KeyAPI)(api) } //Object returns the ObjectAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Object() coreiface.ObjectAPI { - return &ObjectAPI{api, nil} + return (*ObjectAPI)(api) } // Pin returns the PinAPI interface implementation backed by the go-ipfs node func (api *CoreAPI) Pin() coreiface.PinAPI { - return &PinAPI{api, nil} + return (*PinAPI)(api) } // ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the diff --git a/core/coreapi/dag.go b/core/coreapi/dag.go index 443d4542fe1..9ef08eb601e 100644 --- a/core/coreapi/dag.go +++ b/core/coreapi/dag.go @@ -15,10 +15,7 @@ import ( ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ) -type DagAPI struct { - *CoreAPI - *caopts.DagOptions -} +type DagAPI CoreAPI // Put inserts data using specified format and input encoding. Unless used with // `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 } func (api *DagAPI) core() coreiface.CoreAPI { - return api.CoreAPI + return (*CoreAPI)(api) } diff --git a/core/coreapi/dag_test.go b/core/coreapi/dag_test.go index 712509b6d21..9f3c0786f6f 100644 --- a/core/coreapi/dag_test.go +++ b/core/coreapi/dag_test.go @@ -9,6 +9,8 @@ import ( coreapi "github.com/ipfs/go-ipfs/core/coreapi" mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash" + + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) var ( @@ -45,7 +47,7 @@ func TestPutWithHash(t *testing.T) { t.Error(err) } - res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`), api.Dag().WithHash(mh.ID, -1)) + res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`), opt.Dag.Hash(mh.ID, -1)) if err != nil { t.Error(err) } diff --git a/core/coreapi/interface/block.go b/core/coreapi/interface/block.go index f38a664c302..a9e577d7655 100644 --- a/core/coreapi/interface/block.go +++ b/core/coreapi/interface/block.go @@ -21,15 +21,6 @@ type BlockAPI interface { // Put imports raw block data, hashing it using specified settings. Put(context.Context, io.Reader, ...options.BlockPutOption) (Path, error) - // WithFormat is an option for Put which specifies the multicodec to use to - // serialize the object. Default is "v0" - WithFormat(codec string) options.BlockPutOption - - // WithHash is an option for Put which specifies the multihash settings to use - // when hashing the object. Default is mh.SHA2_256 (0x12). - // If mhLen is set to -1, default length for the hash will be used - WithHash(mhType uint64, mhLen int) options.BlockPutOption - // Get attempts to resolve the path and return a reader for data in the block Get(context.Context, Path) (io.Reader, error) @@ -40,10 +31,6 @@ type BlockAPI interface { // will be returned Rm(context.Context, Path, ...options.BlockRmOption) error - // WithForce is an option for Rm which, when set to true, will ignore - // non-existing blocks - WithForce(force bool) options.BlockRmOption - // Stat returns information on Stat(context.Context, Path) (BlockStat, error) } diff --git a/core/coreapi/interface/dag.go b/core/coreapi/interface/dag.go index 1635d71b1cb..f20c88f25ae 100644 --- a/core/coreapi/interface/dag.go +++ b/core/coreapi/interface/dag.go @@ -16,27 +16,9 @@ type DagAPI interface { // "sha256" are used. Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error) - // WithInputEnc is an option for Put which specifies the input encoding of the - // data. Default is "json", most formats/codecs support "raw" - WithInputEnc(enc string) options.DagPutOption - - // WithCodec is an option for Put which specifies the multicodec to use to - // serialize the object. Default is cid.DagCBOR (0x71) - WithCodec(codec uint64) options.DagPutOption - - // WithHash is an option for Put which specifies the multihash settings to use - // when hashing the object. Default is based on the codec used - // (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for - // the hash will be used - WithHash(mhType uint64, mhLen int) options.DagPutOption - // Get attempts to resolve and get the node specified by the path Get(ctx context.Context, path Path) (ipld.Node, error) // Tree returns list of paths within a node specified by the path. Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error) - - // WithDepth is an option for Tree which specifies maximum depth of the - // returned tree. Default is -1 (no depth limit) - WithDepth(depth int) options.DagTreeOption } diff --git a/core/coreapi/interface/key.go b/core/coreapi/interface/key.go index 730e855d78e..928aa265f8c 100644 --- a/core/coreapi/interface/key.go +++ b/core/coreapi/interface/key.go @@ -20,29 +20,10 @@ type KeyAPI interface { // name and returns a base58 encoded multihash of it's public key Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error) - // WithType is an option for Generate which specifies which algorithm - // should be used for the key. Default is options.RSAKey - // - // Supported key types: - // * options.RSAKey - // * options.Ed25519Key - WithType(algorithm string) options.KeyGenerateOption - - // WithSize is an option for Generate which specifies the size of the key to - // generated. Default is -1 - // - // value of -1 means 'use default size for key type': - // * 2048 for RSA - WithSize(size int) options.KeyGenerateOption - // Rename renames oldName key to newName. Returns the key and whether another // key was overwritten, or an error Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error) - // WithForce is an option for Rename which specifies whether to allow to - // replace existing keys. - WithForce(force bool) options.KeyRenameOption - // List lists keys stored in keystore List(ctx context.Context) ([]Key, error) diff --git a/core/coreapi/interface/name.go b/core/coreapi/interface/name.go index 6d17d840ad8..a6aad0c3e6f 100644 --- a/core/coreapi/interface/name.go +++ b/core/coreapi/interface/name.go @@ -2,7 +2,6 @@ package iface import ( "context" - "time" options "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) @@ -27,29 +26,6 @@ type NameAPI interface { // Publish announces new IPNS name Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error) - // WithValidTime is an option for Publish which specifies for how long the - // entry will remain valid. Default value is 24h - WithValidTime(validTime time.Duration) options.NamePublishOption - - // WithKey is an option for Publish which specifies the key to use for - // publishing. Default value is "self" which is the node's own PeerID. - // The key parameter must be either PeerID or keystore key alias. - // - // You can use KeyAPI to list and generate more names and their respective keys. - WithKey(key string) options.NamePublishOption - // Resolve attempts to resolve the newest version of the specified name Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error) - - // WithRecursive is an option for Resolve which specifies whether to perform a - // recursive lookup. Default value is false - WithRecursive(recursive bool) options.NameResolveOption - - // WithLocal is an option for Resolve which specifies if the lookup should be - // offline. Default value is false - WithLocal(local bool) options.NameResolveOption - - // WithCache is an option for Resolve which specifies if cache should be used. - // Default value is true - WithCache(cache bool) options.NameResolveOption } diff --git a/core/coreapi/interface/object.go b/core/coreapi/interface/object.go index 75837f93ec6..548b15a7369 100644 --- a/core/coreapi/interface/object.go +++ b/core/coreapi/interface/object.go @@ -37,33 +37,9 @@ type ObjectAPI interface { // New creates new, empty (by default) dag-node. New(context.Context, ...options.ObjectNewOption) (ipld.Node, error) - // WithType is an option for New which allows to change the type of created - // dag node. - // - // Supported types: - // * 'empty' - Empty node - // * 'unixfs-dir' - Empty UnixFS directory - WithType(string) options.ObjectNewOption - // Put imports the data into merkledag Put(context.Context, io.Reader, ...options.ObjectPutOption) (Path, error) - // WithInputEnc is an option for Put which specifies the input encoding of the - // data. Default is "json". - // - // Supported encodings: - // * "protobuf" - // * "json" - WithInputEnc(e string) options.ObjectPutOption - - // WithDataType specifies the encoding of data field when using Josn or XML - // input encoding. - // - // Supported types: - // * "text" (default) - // * "base64" - WithDataType(t string) options.ObjectPutOption - // Get returns the node for the path Get(context.Context, Path) (ipld.Node, error) @@ -81,10 +57,6 @@ type ObjectAPI interface { // with WithCreate option). AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error) - // WithCreate is an option for AddLink which specifies whether create required - // directories for the child - WithCreate(create bool) options.ObjectAddLinkOption - // RmLink removes a link from the node RmLink(ctx context.Context, base Path, link string) (Path, error) diff --git a/core/coreapi/interface/options/block.go b/core/coreapi/interface/options/block.go index bbb14612f44..20320705e98 100644 --- a/core/coreapi/interface/options/block.go +++ b/core/coreapi/interface/options/block.go @@ -47,16 +47,23 @@ func BlockRmOptions(opts ...BlockRmOption) (*BlockRmSettings, error) { return options, nil } -type BlockOptions struct{} +type blockOpts struct{} -func (api *BlockOptions) WithFormat(codec string) BlockPutOption { +var Block blockOpts + +// Format is an option for Block.Put which specifies the multicodec to use to +// serialize the object. Default is "v0" +func (_ blockOpts) Format(codec string) BlockPutOption { return func(settings *BlockPutSettings) error { settings.Codec = codec return nil } } -func (api *BlockOptions) WithHash(mhType uint64, mhLen int) BlockPutOption { +// Hash is an option for Block.Put which specifies the multihash settings to use +// when hashing the object. Default is mh.SHA2_256 (0x12). +// If mhLen is set to -1, default length for the hash will be used +func (_ blockOpts) Hash(mhType uint64, mhLen int) BlockPutOption { return func(settings *BlockPutSettings) error { settings.MhType = mhType settings.MhLength = mhLen @@ -64,7 +71,9 @@ func (api *BlockOptions) WithHash(mhType uint64, mhLen int) BlockPutOption { } } -func (api *BlockOptions) WithForce(force bool) BlockRmOption { +// Force is an option for Block.Rm which, when set to true, will ignore +// non-existing blocks +func (_ blockOpts) Force(force bool) BlockRmOption { return func(settings *BlockRmSettings) error { settings.Force = force return nil diff --git a/core/coreapi/interface/options/dag.go b/core/coreapi/interface/options/dag.go index b56fcd81a6e..ec258cf95ff 100644 --- a/core/coreapi/interface/options/dag.go +++ b/core/coreapi/interface/options/dag.go @@ -51,23 +51,33 @@ func DagTreeOptions(opts ...DagTreeOption) (*DagTreeSettings, error) { return options, nil } -type DagOptions struct{} +type dagOpts struct{} -func (api *DagOptions) WithInputEnc(enc string) DagPutOption { +var Dag dagOpts + +// InputEnc is an option for Dag.Put which specifies the input encoding of the +// data. Default is "json", most formats/codecs support "raw" +func (_ dagOpts) InputEnc(enc string) DagPutOption { return func(settings *DagPutSettings) error { settings.InputEnc = enc return nil } } -func (api *DagOptions) WithCodec(codec uint64) DagPutOption { +// Codec is an option for Dag.Put which specifies the multicodec to use to +// serialize the object. Default is cid.DagCBOR (0x71) +func (_ dagOpts) Codec(codec uint64) DagPutOption { return func(settings *DagPutSettings) error { settings.Codec = codec return nil } } -func (api *DagOptions) WithHash(mhType uint64, mhLen int) DagPutOption { +// Hash is an option for Dag.Put which specifies the multihash settings to use +// when hashing the object. Default is based on the codec used +// (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for +// the hash will be used +func (_ dagOpts) Hash(mhType uint64, mhLen int) DagPutOption { return func(settings *DagPutSettings) error { settings.MhType = mhType settings.MhLength = mhLen @@ -75,7 +85,9 @@ func (api *DagOptions) WithHash(mhType uint64, mhLen int) DagPutOption { } } -func (api *DagOptions) WithDepth(depth int) DagTreeOption { +// Depth is an option for Dag.Tree which specifies maximum depth of the +// returned tree. Default is -1 (no depth limit) +func (_ dagOpts) Depth(depth int) DagTreeOption { return func(settings *DagTreeSettings) error { settings.Depth = depth return nil diff --git a/core/coreapi/interface/options/key.go b/core/coreapi/interface/options/key.go index 114361875a5..a29261d1448 100644 --- a/core/coreapi/interface/options/key.go +++ b/core/coreapi/interface/options/key.go @@ -48,23 +48,38 @@ func KeyRenameOptions(opts ...KeyRenameOption) (*KeyRenameSettings, error) { return options, nil } -type KeyOptions struct{} +type keyOpts struct{} -func (api *KeyOptions) WithType(algorithm string) KeyGenerateOption { +var Key keyOpts + +// Type is an option for Key.Generate which specifies which algorithm +// should be used for the key. Default is options.RSAKey +// +// Supported key types: +// * options.RSAKey +// * options.Ed25519Key +func (_ keyOpts) Type(algorithm string) KeyGenerateOption { return func(settings *KeyGenerateSettings) error { settings.Algorithm = algorithm return nil } } -func (api *KeyOptions) WithSize(size int) KeyGenerateOption { +// Size is an option for Key.Generate which specifies the size of the key to +// generated. Default is -1 +// +// value of -1 means 'use default size for key type': +// * 2048 for RSA +func (_ keyOpts) Size(size int) KeyGenerateOption { return func(settings *KeyGenerateSettings) error { settings.Size = size return nil } } -func (api *KeyOptions) WithForce(force bool) KeyRenameOption { +// Force is an option for Key.Rename which specifies whether to allow to +// replace existing keys. +func (_ keyOpts) Force(force bool) KeyRenameOption { return func(settings *KeyRenameSettings) error { settings.Force = force return nil diff --git a/core/coreapi/interface/options/name.go b/core/coreapi/interface/options/name.go index 9f8aaafc83e..1f6de0ee32f 100644 --- a/core/coreapi/interface/options/name.go +++ b/core/coreapi/interface/options/name.go @@ -55,37 +55,52 @@ func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) return options, nil } -type NameOptions struct{} +type nameOpts struct{} -func (api *NameOptions) WithValidTime(validTime time.Duration) NamePublishOption { +var Name nameOpts + +// ValidTime is an option for Name.Publish which specifies for how long the +// entry will remain valid. Default value is 24h +func (_ nameOpts) ValidTime(validTime time.Duration) NamePublishOption { return func(settings *NamePublishSettings) error { settings.ValidTime = validTime return nil } } -func (api *NameOptions) WithKey(key string) NamePublishOption { +// Key is an option for Name.Publish which specifies the key to use for +// publishing. Default value is "self" which is the node's own PeerID. +// The key parameter must be either PeerID or keystore key alias. +// +// You can use KeyAPI to list and generate more names and their respective keys. +func (_ nameOpts) Key(key string) NamePublishOption { return func(settings *NamePublishSettings) error { settings.Key = key return nil } } -func (api *NameOptions) WithRecursive(recursive bool) NameResolveOption { +// Recursive is an option for Name.Resolve which specifies whether to perform a +// recursive lookup. Default value is false +func (_ nameOpts) Recursive(recursive bool) NameResolveOption { return func(settings *NameResolveSettings) error { settings.Recursive = recursive return nil } } -func (api *NameOptions) WithLocal(local bool) NameResolveOption { +// Local is an option for Name.Resolve which specifies if the lookup should be +// offline. Default value is false +func (_ nameOpts) Local(local bool) NameResolveOption { return func(settings *NameResolveSettings) error { settings.Local = local return nil } } -func (api *NameOptions) WithCache(cache bool) NameResolveOption { +// Cache is an option for Name.Resolve which specifies if cache should be used. +// Default value is true +func (_ nameOpts) Cache(cache bool) NameResolveOption { return func(settings *NameResolveSettings) error { settings.Cache = cache return nil diff --git a/core/coreapi/interface/options/object.go b/core/coreapi/interface/options/object.go index 9c8c9a9ddd1..00e41d28b06 100644 --- a/core/coreapi/interface/options/object.go +++ b/core/coreapi/interface/options/object.go @@ -60,30 +60,52 @@ func ObjectAddLinkOptions(opts ...ObjectAddLinkOption) (*ObjectAddLinkSettings, return options, nil } -type ObjectOptions struct{} +type objectOpts struct{} -func (api *ObjectOptions) WithType(t string) ObjectNewOption { +var Object objectOpts + +// Type is an option for Object.New which allows to change the type of created +// dag node. +// +// Supported types: +// * 'empty' - Empty node +// * 'unixfs-dir' - Empty UnixFS directory +func (_ objectOpts) Type(t string) ObjectNewOption { return func(settings *ObjectNewSettings) error { settings.Type = t return nil } } -func (api *ObjectOptions) WithInputEnc(e string) ObjectPutOption { +// InputEnc is an option for Object.Put which specifies the input encoding of the +// data. Default is "json". +// +// Supported encodings: +// * "protobuf" +// * "json" +func (_ objectOpts) InputEnc(e string) ObjectPutOption { return func(settings *ObjectPutSettings) error { settings.InputEnc = e return nil } } -func (api *ObjectOptions) WithDataType(t string) ObjectPutOption { +// DataType is an option for Object.Put which specifies the encoding of data +// field when using Json or XML input encoding. +// +// Supported types: +// * "text" (default) +// * "base64" +func (_ objectOpts) DataType(t string) ObjectPutOption { return func(settings *ObjectPutSettings) error { settings.DataType = t return nil } } -func (api *ObjectOptions) WithCreate(create bool) ObjectAddLinkOption { +// Create is an option for Object.AddLink which specifies whether create required +// directories for the child +func (_ objectOpts) Create(create bool) ObjectAddLinkOption { return func(settings *ObjectAddLinkSettings) error { settings.Create = create return nil diff --git a/core/coreapi/interface/options/pin.go b/core/coreapi/interface/options/pin.go index f97f7b16ee1..680ed391d36 100644 --- a/core/coreapi/interface/options/pin.go +++ b/core/coreapi/interface/options/pin.go @@ -61,23 +61,38 @@ func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) { return options, nil } -type PinOptions struct{} +type pinOpts struct{} -func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption { +var Pin pinOpts + +// 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 { return func(settings *PinAddSettings) error { settings.Recursive = recucsive return nil } } -func (api *PinOptions) WithType(t string) PinLsOption { +// Type is an option for Pin.Ls which allows to specify which pin types should +// be returned +// +// Supported values: +// * "direct" - directly pinned objects +// * "recursive" - roots of recursive pins +// * "indirect" - indirectly pinned objects (referenced by recursively pinned +// objects) +// * "all" - all pinned objects (default) +func (_ pinOpts) Type(t string) PinLsOption { return func(settings *PinLsSettings) error { settings.Type = t return nil } } -func (api *PinOptions) WithUnpin(unpin bool) PinUpdateOption { +// Unpin is an option for Pin.Update which specifies whether to remove the old pin. +// Default is true. +func (_ pinOpts) Unpin(unpin bool) PinUpdateOption { return func(settings *PinUpdateSettings) error { settings.Unpin = unpin return nil diff --git a/core/coreapi/interface/pin.go b/core/coreapi/interface/pin.go index 47a5a0bb282..5994c758686 100644 --- a/core/coreapi/interface/pin.go +++ b/core/coreapi/interface/pin.go @@ -39,24 +39,9 @@ type PinAPI interface { // tree Add(context.Context, Path, ...options.PinAddOption) error - // WithRecursive is an option for Add which specifies whether to pin an entire - // object tree or just one object. Default: true - WithRecursive(bool) options.PinAddOption - // Ls returns list of pinned objects on this node Ls(context.Context, ...options.PinLsOption) ([]Pin, error) - // WithType is an option for Ls which allows to specify which pin types should - // be returned - // - // Supported values: - // * "direct" - directly pinned objects - // * "recursive" - roots of recursive pins - // * "indirect" - indirectly pinned objects (referenced by recursively pinned - // objects) - // * "all" - all pinned objects (default) - WithType(string) options.PinLsOption - // Rm removes pin for object specified by the path Rm(context.Context, Path) error diff --git a/core/coreapi/key.go b/core/coreapi/key.go index 06bdcae440e..7e8268e6cbd 100644 --- a/core/coreapi/key.go +++ b/core/coreapi/key.go @@ -14,10 +14,7 @@ import ( crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" ) -type KeyAPI struct { - *CoreAPI - *caopts.KeyOptions -} +type KeyAPI CoreAPI type key struct { name string @@ -203,7 +200,3 @@ func (api *KeyAPI) Remove(ctx context.Context, name string) (coreiface.Path, err return (&key{"", pid.Pretty()}).Path(), nil } - -func (api *KeyAPI) core() coreiface.CoreAPI { - return api.CoreAPI -} diff --git a/core/coreapi/key_test.go b/core/coreapi/key_test.go index 92d4c8d4a33..6bcdfb04be5 100644 --- a/core/coreapi/key_test.go +++ b/core/coreapi/key_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - opts "github.com/ipfs/go-ipfs/core/coreapi/interface/options" + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) func TestListSelf(t *testing.T) { @@ -53,7 +53,7 @@ func TestRenameSelf(t *testing.T) { } } - _, _, err = api.Key().Rename(ctx, "self", "foo", api.Key().WithForce(true)) + _, _, err = api.Key().Rename(ctx, "self", "foo", opt.Key.Force(true)) if err == nil { t.Error("expected error to not be nil") } else { @@ -110,7 +110,7 @@ func TestGenerateSize(t *testing.T) { t.Error(err) } - k, err := api.Key().Generate(ctx, "foo", api.Key().WithSize(1024)) + k, err := api.Key().Generate(ctx, "foo", opt.Key.Size(1024)) if err != nil { t.Fatal(err) return @@ -132,7 +132,7 @@ func TestGenerateType(t *testing.T) { t.Error(err) } - k, err := api.Key().Generate(ctx, "bar", api.Key().WithType(opts.Ed25519Key)) + k, err := api.Key().Generate(ctx, "bar", opt.Key.Type(opt.Ed25519Key)) if err != nil { t.Fatal(err) return @@ -288,7 +288,7 @@ func TestRenameToSelfForce(t *testing.T) { return } - _, _, err = api.Key().Rename(ctx, "foo", "self", api.Key().WithForce(true)) + _, _, err = api.Key().Rename(ctx, "foo", "self", opt.Key.Force(true)) if err == nil { t.Error("expected error to not be nil") } else { @@ -346,7 +346,7 @@ func TestRenameOverwrite(t *testing.T) { return } - k, overwrote, err := api.Key().Rename(ctx, "foo", "bar", api.Key().WithForce(true)) + k, overwrote, err := api.Key().Rename(ctx, "foo", "bar", opt.Key.Force(true)) if err != nil { t.Fatal(err) return diff --git a/core/coreapi/name.go b/core/coreapi/name.go index e99545acd57..80bf9821b98 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -19,10 +19,7 @@ import ( crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" ) -type NameAPI struct { - *CoreAPI - *caopts.NameOptions -} +type NameAPI CoreAPI type ipnsEntry struct { name string @@ -134,10 +131,6 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam return &path{path: output}, nil } -func (api *NameAPI) core() coreiface.CoreAPI { - return api.CoreAPI -} - func keylookup(n *core.IpfsNode, k string) (crypto.PrivKey, error) { res, err := n.GetKey(k) if res != nil { diff --git a/core/coreapi/name_test.go b/core/coreapi/name_test.go index 74fdacda41b..bfb1802df8e 100644 --- a/core/coreapi/name_test.go +++ b/core/coreapi/name_test.go @@ -10,6 +10,7 @@ import ( ipath "github.com/ipfs/go-ipfs/path" coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface" + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) var rnd = rand.New(rand.NewSource(0x62796532303137)) @@ -77,7 +78,7 @@ func TestBasicPublishResolveKey(t *testing.T) { return } - e, err := api.Name().Publish(ctx, p, api.Name().WithKey(k.Name())) + e, err := api.Name().Publish(ctx, p, opt.Name.Key(k.Name())) if err != nil { t.Fatal(err) return @@ -118,7 +119,7 @@ func TestBasicPublishResolveTimeout(t *testing.T) { return } - e, err := api.Name().Publish(ctx, p, api.Name().WithValidTime(time.Millisecond*100)) + e, err := api.Name().Publish(ctx, p, opt.Name.ValidTime(time.Millisecond*100)) if err != nil { t.Fatal(err) return diff --git a/core/coreapi/object.go b/core/coreapi/object.go index 00edb31013f..6cfd303b713 100644 --- a/core/coreapi/object.go +++ b/core/coreapi/object.go @@ -23,10 +23,7 @@ import ( const inputLimit = 2 << 20 -type ObjectAPI struct { - *CoreAPI - *caopts.ObjectOptions -} +type ObjectAPI CoreAPI type Link struct { Name, Hash string @@ -288,7 +285,7 @@ func (api *ObjectAPI) patchData(ctx context.Context, path coreiface.Path, r io.R } func (api *ObjectAPI) core() coreiface.CoreAPI { - return api.CoreAPI + return (*CoreAPI)(api) } func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error) { diff --git a/core/coreapi/object_test.go b/core/coreapi/object_test.go index a06d0e16591..3d0a5434931 100644 --- a/core/coreapi/object_test.go +++ b/core/coreapi/object_test.go @@ -7,6 +7,8 @@ import ( "io/ioutil" "strings" "testing" + + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) func TestNew(t *testing.T) { @@ -21,7 +23,7 @@ func TestNew(t *testing.T) { t.Fatal(err) } - dirNode, err := api.Object().New(ctx, api.Object().WithType("unixfs-dir")) + dirNode, err := api.Object().New(ctx, opt.Object.Type("unixfs-dir")) if err != nil { t.Fatal(err) } @@ -47,7 +49,7 @@ func TestObjectPut(t *testing.T) { t.Fatal(err) } - p2, err := api.Object().Put(ctx, strings.NewReader(`{"Data":"YmFy"}`), api.Object().WithDataType("base64")) //bar + p2, err := api.Object().Put(ctx, strings.NewReader(`{"Data":"YmFy"}`), opt.Object.DataType("base64")) //bar if err != nil { t.Fatal(err) } @@ -57,7 +59,7 @@ func TestObjectPut(t *testing.T) { t.Fatal(err) } - p3, err := api.Object().Put(ctx, bytes.NewReader(pbBytes), api.Object().WithInputEnc("protobuf")) + p3, err := api.Object().Put(ctx, bytes.NewReader(pbBytes), opt.Object.InputEnc("protobuf")) if err != nil { t.Fatal(err) } @@ -271,7 +273,7 @@ func TestObjectAddLinkCreate(t *testing.T) { t.Fatalf("unexpected error: %s", err.Error()) } - p3, err = api.Object().AddLink(ctx, p2, "abc/d", p2, api.Object().WithCreate(true)) + p3, err = api.Object().AddLink(ctx, p2, "abc/d", p2, opt.Object.Create(true)) if err != nil { t.Fatal(err) } diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index 61768999e07..0606200daf2 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -16,10 +16,7 @@ import ( ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ) -type PinAPI struct { - *CoreAPI - *caopts.PinOptions -} +type PinAPI CoreAPI func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.PinAddOption) error { settings, err := caopts.PinAddOptions(opts...) diff --git a/core/coreapi/pin_test.go b/core/coreapi/pin_test.go index 6ab0e5350bc..5f3b5d855c6 100644 --- a/core/coreapi/pin_test.go +++ b/core/coreapi/pin_test.go @@ -4,6 +4,8 @@ import ( "context" "strings" "testing" + + opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options" ) func TestPinAdd(t *testing.T) { @@ -105,7 +107,7 @@ func TestPinRecursive(t *testing.T) { t.Error(err) } - err = api.Pin().Add(ctx, p3, api.Pin().WithRecursive(false)) + err = api.Pin().Add(ctx, p3, opt.Pin.Recursive(false)) if err != nil { t.Error(err) } @@ -119,7 +121,7 @@ func TestPinRecursive(t *testing.T) { t.Errorf("unexpected pin list len: %d", len(list)) } - list, err = api.Pin().Ls(ctx, api.Pin().WithType("direct")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type("direct")) if err != nil { t.Fatal(err) } @@ -132,7 +134,7 @@ func TestPinRecursive(t *testing.T) { t.Error("unexpected path") } - list, err = api.Pin().Ls(ctx, api.Pin().WithType("recursive")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type("recursive")) if err != nil { t.Fatal(err) } @@ -145,7 +147,7 @@ func TestPinRecursive(t *testing.T) { t.Error("unexpected path") } - list, err = api.Pin().Ls(ctx, api.Pin().WithType("indirect")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type("indirect")) if err != nil { t.Fatal(err) }