coreapi: remove options from interfaces
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@38ccf0555876033759418de2c43b5d9c727b2c19 This commit was moved from ipfs/boxo@595afb8260f48d77dfff80a7d4a191f185adfb87
Łukasz Magiera committed
Mar 11, 2018 at 18:55 UTC
5e488491670bdb45a3fa957b624f44a068cb40a5
12 files changed
+116
-145
core/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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/coreiface/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