From eb537a7c8b3047d5c40dc0ecda810cb8eda71a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 15 Dec 2017 01:34:49 +0100 Subject: [PATCH] docs/coreapi: Add some documentation to CoreAPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- core/coreapi/coreapi.go | 1 + core/coreapi/interface/interface.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index a9db25db1..bdc9d7e61 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -15,6 +15,7 @@ type CoreAPI struct { node *core.IpfsNode } +// NewCoreAPI creates new instance of IPFS CoreAPI backed by go-ipfs Node func NewCoreAPI(n *core.IpfsNode) coreiface.CoreAPI { api := &CoreAPI{n} return api diff --git a/core/coreapi/interface/interface.go b/core/coreapi/interface/interface.go index 78a64dd40..87e9fcd0f 100644 --- a/core/coreapi/interface/interface.go +++ b/core/coreapi/interface/interface.go @@ -1,3 +1,5 @@ +// Package iface defines IPFS Core API which is a set of interfaces used to +// interact with IPFS nodes. package iface import ( @@ -9,6 +11,8 @@ import ( ipld "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" ) +// Path is a generic wrapper for paths used in the API. A path can be resolved +// to a CID using one of Resolve functions in the API. type Path interface { String() string Cid() *cid.Cid @@ -26,15 +30,28 @@ type Reader interface { io.Closer } +// CoreAPI defines an unified interface to IPFS for Go programs. type CoreAPI interface { + // Unixfs returns an implementation of Unixfs API Unixfs() UnixfsAPI + + // ResolvePath resolves the path using Unixfs resolver ResolvePath(context.Context, Path) (Path, error) + + // ResolveNode resolves the path (if not resolved already) using Unixfs + // resolver, gets and returns the resolved Node ResolveNode(context.Context, Path) (Node, error) } +// UnixfsAPI is the basic interface to immutable files in IPFS type UnixfsAPI interface { + // Add imports the data from the reader into merkledag file Add(context.Context, io.Reader) (Path, error) + + // Cat returns a reader for the file Cat(context.Context, Path) (Reader, error) + + // Ls returns the list of links in a directory Ls(context.Context, Path) ([]*Link, error) }