mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
coreapi: don't alias ipld types
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
20b59ec1ec
commit
eff69bbf37
@ -59,11 +59,11 @@ func (api *CoreAPI) Pin() coreiface.PinAPI {
|
||||
|
||||
// ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the
|
||||
// resolved Node.
|
||||
func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (coreiface.Node, error) {
|
||||
func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (ipld.Node, error) {
|
||||
return resolveNode(ctx, api.node.DAG, api.node.Namesys, p)
|
||||
}
|
||||
|
||||
func resolveNode(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSystem, p coreiface.Path) (coreiface.Node, error) {
|
||||
func resolveNode(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSystem, p coreiface.Path) (ipld.Node, error) {
|
||||
p, err := resolvePath(ctx, ng, nsys, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
coredag "github.com/ipfs/go-ipfs/core/coredag"
|
||||
|
||||
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
|
||||
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
||||
)
|
||||
|
||||
type DagAPI struct {
|
||||
@ -50,7 +51,7 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut
|
||||
}
|
||||
|
||||
// Get resolves `path` using Unixfs resolver, returns the resolved Node.
|
||||
func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (coreiface.Node, error) {
|
||||
func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (ipld.Node, error) {
|
||||
return api.core().ResolveNode(ctx, path)
|
||||
}
|
||||
|
||||
|
||||
@ -30,11 +30,6 @@ type Path interface {
|
||||
Resolved() bool
|
||||
}
|
||||
|
||||
// TODO: should we really copy these?
|
||||
// if we didn't, godoc would generate nice links straight to go-ipld-format
|
||||
type Node ipld.Node
|
||||
type Link ipld.Link
|
||||
|
||||
type Reader interface {
|
||||
io.ReadSeeker
|
||||
io.Closer
|
||||
@ -114,7 +109,7 @@ type CoreAPI interface {
|
||||
|
||||
// ResolveNode resolves the path (if not resolved already) using Unixfs
|
||||
// resolver, gets and returns the resolved Node
|
||||
ResolveNode(context.Context, Path) (Node, error)
|
||||
ResolveNode(context.Context, Path) (ipld.Node, error)
|
||||
}
|
||||
|
||||
// UnixfsAPI is the basic interface to immutable files in IPFS
|
||||
@ -126,7 +121,7 @@ type UnixfsAPI interface {
|
||||
Cat(context.Context, Path) (Reader, error)
|
||||
|
||||
// Ls returns the list of links in a directory
|
||||
Ls(context.Context, Path) ([]*Link, error)
|
||||
Ls(context.Context, Path) ([]*ipld.Link, error)
|
||||
}
|
||||
|
||||
// BlockAPI specifies the interface to the block layer
|
||||
@ -183,7 +178,7 @@ type DagAPI interface {
|
||||
WithHash(mhType uint64, mhLen int) options.DagPutOption
|
||||
|
||||
// Get attempts to resolve and get the node specified by the path
|
||||
Get(ctx context.Context, path Path) (Node, error)
|
||||
Get(ctx context.Context, path Path) (ipld.Node, error)
|
||||
|
||||
// Tree returns list of paths within a node specified by the path.
|
||||
Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
|
||||
@ -272,7 +267,7 @@ type KeyAPI interface {
|
||||
// for manipulating MerkleDAG data structures.
|
||||
type ObjectAPI interface {
|
||||
// New creates new, empty (by default) dag-node.
|
||||
New(context.Context, ...options.ObjectNewOption) (Node, error)
|
||||
New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
|
||||
|
||||
// WithType is an option for New which allows to change the type of created
|
||||
// dag node.
|
||||
@ -302,13 +297,13 @@ type ObjectAPI interface {
|
||||
WithDataType(t string) options.ObjectPutOption
|
||||
|
||||
// Get returns the node for the path
|
||||
Get(context.Context, Path) (Node, error)
|
||||
Get(context.Context, Path) (ipld.Node, error)
|
||||
|
||||
// Data returns reader for data of the node
|
||||
Data(context.Context, Path) (io.Reader, error)
|
||||
|
||||
// Links returns lint or links the node contains
|
||||
Links(context.Context, Path) ([]*Link, error)
|
||||
Links(context.Context, Path) ([]*ipld.Link, error)
|
||||
|
||||
// Stat returns information about the node
|
||||
Stat(context.Context, Path) (*ObjectStat, error)
|
||||
|
||||
@ -38,7 +38,7 @@ type Node struct {
|
||||
Data string
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (coreiface.Node, error) {
|
||||
func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (ipld.Node, error) {
|
||||
options, err := caopts.ObjectNewOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -127,7 +127,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
|
||||
return ParseCid(dagnode.Cid()), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Get(ctx context.Context, path coreiface.Path) (coreiface.Node, error) {
|
||||
func (api *ObjectAPI) Get(ctx context.Context, path coreiface.Path) (ipld.Node, error) {
|
||||
return api.core().ResolveNode(ctx, path)
|
||||
}
|
||||
|
||||
@ -145,16 +145,16 @@ func (api *ObjectAPI) Data(ctx context.Context, path coreiface.Path) (io.Reader,
|
||||
return bytes.NewReader(pbnd.Data()), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Links(ctx context.Context, path coreiface.Path) ([]*coreiface.Link, error) {
|
||||
func (api *ObjectAPI) Links(ctx context.Context, path coreiface.Path) ([]*ipld.Link, error) {
|
||||
nd, err := api.core().ResolveNode(ctx, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
links := nd.Links()
|
||||
out := make([]*coreiface.Link, len(links))
|
||||
out := make([]*ipld.Link, len(links))
|
||||
for n, l := range links {
|
||||
out[n] = (*coreiface.Link)(l)
|
||||
out[n] = (*ipld.Link)(l)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
|
||||
@ -48,7 +48,7 @@ func (api *UnixfsAPI) Cat(ctx context.Context, p coreiface.Path) (coreiface.Read
|
||||
|
||||
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
|
||||
// `<link base58 hash> <link size in bytes> <link name>`
|
||||
func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*coreiface.Link, error) {
|
||||
func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*ipld.Link, error) {
|
||||
dagnode, err := api.core().ResolveNode(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -69,9 +69,9 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*coreiface.Li
|
||||
return nil, err
|
||||
}
|
||||
|
||||
links := make([]*coreiface.Link, len(ndlinks))
|
||||
links := make([]*ipld.Link, len(ndlinks))
|
||||
for i, l := range ndlinks {
|
||||
links[i] = &coreiface.Link{Name: l.Name, Size: l.Size, Cid: l.Cid}
|
||||
links[i] = &ipld.Link{Name: l.Name, Size: l.Size, Cid: l.Cid}
|
||||
}
|
||||
return links, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user