@cryptotaxi247 / kubo / commits / eb537a7c8

docs/coreapi: Add some documentation to CoreAPI

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Dec 15, 2017 at 01:34 UTC eb537a7c8b3047d5c40dc0ecda810cb8eda71a4c
2 files changed +18
core/coreapi/coreapi.go
+1
@@ -15,6 +15,7 @@ type CoreAPI struct {
15 node *core.IpfsNode
16 }
17
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
core/coreapi/interface/interface.go
+17
@@ -1,3 +1,5 @@
1 +// Package iface defines IPFS Core API which is a set of interfaces used to
2 +// interact with IPFS nodes.
3 package iface
4
5 import (
@@ -9,6 +11,8 @@ import (
11 ipld "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
12 )
13
14 +// Path is a generic wrapper for paths used in the API. A path can be resolved
15 +// to a CID using one of Resolve functions in the API.
16 type Path interface {
17 String() string
18 Cid() *cid.Cid
@@ -26,15 +30,28 @@ type Reader interface {
30 io.Closer
31 }
32
33 +// CoreAPI defines an unified interface to IPFS for Go programs.
34 type CoreAPI interface {
35 + // Unixfs returns an implementation of Unixfs API
36 Unixfs() UnixfsAPI
37 +
38 + // ResolvePath resolves the path using Unixfs resolver
39 ResolvePath(context.Context, Path) (Path, error)
40 +
41 + // ResolveNode resolves the path (if not resolved already) using Unixfs
42 + // resolver, gets and returns the resolved Node
43 ResolveNode(context.Context, Path) (Node, error)
44 }
45
46 +// UnixfsAPI is the basic interface to immutable files in IPFS
47 type UnixfsAPI interface {
48 + // Add imports the data from the reader into merkledag file
49 Add(context.Context, io.Reader) (Path, error)
50 +
51 + // Cat returns a reader for the file
52 Cat(context.Context, Path) (Reader, error)
53 +
54 + // Ls returns the list of links in a directory
55 Ls(context.Context, Path) ([]*Link, error)
56 }
57