coreapi: don't alias ipld types
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 10, 2018 at 18:31 UTC
eff69bbf370d6cbf18d7c3b8b4d25c3cf78dc381
5 files changed
+18
-22
core/coreapi/coreapi.go
+2
-2
@@ -59,11 +59,11 @@ func (api *CoreAPI) Pin() coreiface.PinAPI {
59
60
// ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the
61
// resolved Node.
62
-func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (coreiface.Node, error) {
62
+func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (ipld.Node, error) {
63
return resolveNode(ctx, api.node.DAG, api.node.Namesys, p)
64
}
65
66
-func resolveNode(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSystem, p coreiface.Path) (coreiface.Node, error) {
66
+func resolveNode(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSystem, p coreiface.Path) (ipld.Node, error) {
67
p, err := resolvePath(ctx, ng, nsys, p)
68
if err != nil {
69
return nil, err
core/coreapi/dag.go
+2
-1
@@ -12,6 +12,7 @@ import (
12
coredag "github.com/ipfs/go-ipfs/core/coredag"
13
14
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
15
+ ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
16
)
17
18
type DagAPI struct {
@@ -50,7 +51,7 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut
51
}
52
53
// Get resolves `path` using Unixfs resolver, returns the resolved Node.
53
-func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (coreiface.Node, error) {
54
+func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (ipld.Node, error) {
55
return api.core().ResolveNode(ctx, path)
56
}
57
core/coreapi/interface/interface.go
+6
-11
@@ -30,11 +30,6 @@ type Path interface {
30
Resolved() bool
31
}
32
33
-// TODO: should we really copy these?
34
-// if we didn't, godoc would generate nice links straight to go-ipld-format
35
-type Node ipld.Node
36
-type Link ipld.Link
37
-
33
type Reader interface {
34
io.ReadSeeker
35
io.Closer
@@ -114,7 +109,7 @@ type CoreAPI interface {
109
110
// ResolveNode resolves the path (if not resolved already) using Unixfs
111
// resolver, gets and returns the resolved Node
117
- ResolveNode(context.Context, Path) (Node, error)
112
+ ResolveNode(context.Context, Path) (ipld.Node, error)
113
}
114
115
// UnixfsAPI is the basic interface to immutable files in IPFS
@@ -126,7 +121,7 @@ type UnixfsAPI interface {
121
Cat(context.Context, Path) (Reader, error)
122
123
// Ls returns the list of links in a directory
129
- Ls(context.Context, Path) ([]*Link, error)
124
+ Ls(context.Context, Path) ([]*ipld.Link, error)
125
}
126
127
// BlockAPI specifies the interface to the block layer
@@ -183,7 +178,7 @@ type DagAPI interface {
178
WithHash(mhType uint64, mhLen int) options.DagPutOption
179
180
// Get attempts to resolve and get the node specified by the path
186
- Get(ctx context.Context, path Path) (Node, error)
181
+ Get(ctx context.Context, path Path) (ipld.Node, error)
182
183
// Tree returns list of paths within a node specified by the path.
184
Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
@@ -272,7 +267,7 @@ type KeyAPI interface {
267
// for manipulating MerkleDAG data structures.
268
type ObjectAPI interface {
269
// New creates new, empty (by default) dag-node.
275
- New(context.Context, ...options.ObjectNewOption) (Node, error)
270
+ New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
271
272
// WithType is an option for New which allows to change the type of created
273
// dag node.
@@ -302,13 +297,13 @@ type ObjectAPI interface {
297
WithDataType(t string) options.ObjectPutOption
298
299
// Get returns the node for the path
305
- Get(context.Context, Path) (Node, error)
300
+ Get(context.Context, Path) (ipld.Node, error)
301
302
// Data returns reader for data of the node
303
Data(context.Context, Path) (io.Reader, error)
304
305
// Links returns lint or links the node contains
311
- Links(context.Context, Path) ([]*Link, error)
306
+ Links(context.Context, Path) ([]*ipld.Link, error)
307
308
// Stat returns information about the node
309
Stat(context.Context, Path) (*ObjectStat, error)
core/coreapi/object.go
+5
-5
@@ -38,7 +38,7 @@ type Node struct {
38
Data string
39
}
40
41
-func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (coreiface.Node, error) {
41
+func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (ipld.Node, error) {
42
options, err := caopts.ObjectNewOptions(opts...)
43
if err != nil {
44
return nil, err
@@ -127,7 +127,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
127
return ParseCid(dagnode.Cid()), nil
128
}
129
130
-func (api *ObjectAPI) Get(ctx context.Context, path coreiface.Path) (coreiface.Node, error) {
130
+func (api *ObjectAPI) Get(ctx context.Context, path coreiface.Path) (ipld.Node, error) {
131
return api.core().ResolveNode(ctx, path)
132
}
133
@@ -145,16 +145,16 @@ func (api *ObjectAPI) Data(ctx context.Context, path coreiface.Path) (io.Reader,
145
return bytes.NewReader(pbnd.Data()), nil
146
}
147
148
-func (api *ObjectAPI) Links(ctx context.Context, path coreiface.Path) ([]*coreiface.Link, error) {
148
+func (api *ObjectAPI) Links(ctx context.Context, path coreiface.Path) ([]*ipld.Link, error) {
149
nd, err := api.core().ResolveNode(ctx, path)
150
if err != nil {
151
return nil, err
152
}
153
154
links := nd.Links()
155
- out := make([]*coreiface.Link, len(links))
155
+ out := make([]*ipld.Link, len(links))
156
for n, l := range links {
157
- out[n] = (*coreiface.Link)(l)
157
+ out[n] = (*ipld.Link)(l)
158
}
159
160
return out, nil
core/coreapi/unixfs.go
+3
-3
@@ -48,7 +48,7 @@ func (api *UnixfsAPI) Cat(ctx context.Context, p coreiface.Path) (coreiface.Read
48
49
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
50
// `<link base58 hash> <link size in bytes> <link name>`
51
-func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*coreiface.Link, error) {
51
+func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*ipld.Link, error) {
52
dagnode, err := api.core().ResolveNode(ctx, p)
53
if err != nil {
54
return nil, err
@@ -69,9 +69,9 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*coreiface.Li
69
return nil, err
70
}
71
72
- links := make([]*coreiface.Link, len(ndlinks))
72
+ links := make([]*ipld.Link, len(ndlinks))
73
for i, l := range ndlinks {
74
- links[i] = &coreiface.Link{Name: l.Name, Size: l.Size, Cid: l.Cid}
74
+ links[i] = &ipld.Link{Name: l.Name, Size: l.Size, Cid: l.Cid}
75
}
76
return links, nil
77
}