Commit 38ccf055 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: remove options from interfaces

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 60fc5696
......@@ -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)
}
......@@ -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
}
......@@ -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)
......
......@@ -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
}
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment