docs for coreapi method impls
License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
ForrestWeston committed
Jan 22, 2018 at 14:43 UTC
1eee9e207d1945ef8a94ac3596924d8437f3eaf8
1 file changed
+12
-1
core/coreapi/coreapi.go
+12
-1
@@ -15,28 +15,34 @@ type CoreAPI struct {
15
node *core.IpfsNode
16
}
17
18
-// NewCoreAPI creates new instance of IPFS CoreAPI backed by go-ipfs Node
18
+// NewCoreAPI creates new instance of IPFS CoreAPI backed by go-ipfs Node.
19
func NewCoreAPI(n *core.IpfsNode) coreiface.CoreAPI {
20
api := &CoreAPI{n}
21
return api
22
}
23
24
+// Unixfs returns the UnixfsAPI interface backed by the go-ipfs node
25
func (api *CoreAPI) Unixfs() coreiface.UnixfsAPI {
26
return (*UnixfsAPI)(api)
27
}
28
29
+// Dag returns the DagAPI interface backed by the go-ipfs node
30
func (api *CoreAPI) Dag() coreiface.DagAPI {
31
return &DagAPI{api, nil}
32
}
33
34
+// Name returns the NameAPI interface backed by the go-ipfs node
35
func (api *CoreAPI) Name() coreiface.NameAPI {
36
return &NameAPI{api, nil}
37
}
38
39
+// Key returns the KeyAPI interface backed by the go-ipfs node
40
func (api *CoreAPI) Key() coreiface.KeyAPI {
41
return &KeyAPI{api, nil}
42
}
43
44
+// ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the
45
+// resolved Node.
46
func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (coreiface.Node, error) {
47
p, err := api.ResolvePath(ctx, p)
48
if err != nil {
@@ -50,6 +56,8 @@ func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (coreifac
56
return node, nil
57
}
58
59
+// ResolvePath resolves the path `p` using Unixfs resolver, returns the
60
+// resolved path.
61
// TODO: store all of ipfspath.Resolver.ResolvePathComponents() in Path
62
func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreiface.Path, error) {
63
if p.Resolved() {
@@ -84,6 +92,7 @@ type path struct {
92
root *cid.Cid
93
}
94
95
+// ParsePath parses path `p` using ipfspath parser, returns the parsed path.
96
func ParsePath(p string) (coreiface.Path, error) {
97
pp, err := ipfspath.ParsePath(p)
98
if err != nil {
@@ -92,10 +101,12 @@ func ParsePath(p string) (coreiface.Path, error) {
101
return &path{path: pp}, nil
102
}
103
104
+// ParseCid parses the path from `c`, retruns the parsed path.
105
func ParseCid(c *cid.Cid) coreiface.Path {
106
return &path{path: ipfspath.FromCid(c), cid: c, root: c}
107
}
108
109
+// ResolvePath parses path from string `p`, returns parsed path.
110
func ResolvedPath(p string, c *cid.Cid, r *cid.Cid) coreiface.Path {
111
return &path{path: ipfspath.FromString(p), cid: c, root: r}
112
}