本文整理汇总了Golang中github.com/ipfs/go-ipfs/core.Resolve函数的典型用法代码示例。如果您正苦于以下问题:Golang Resolve函数的具体用法?Golang Resolve怎么用?Golang Resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Patch
// TODO: extract all this logic from the core/commands/object.go to avoid dupe code
func (s *Shell) Patch(root, action string, args ...string) (string, error) {
p, err := path.ParsePath(root)
if err != nil {
return "", err
}
rootnd, err := core.Resolve(s.ctx, s.node, p)
if err != nil {
return "", err
}
insertpath := args[0]
childhash := args[1]
childpath, err := path.ParsePath(childhash)
if err != nil {
return "", err
}
nnode, err := core.Resolve(s.ctx, s.node, childpath)
if err != nil {
return "", err
}
e := dagutils.NewDagEditor(rootnd, s.node.DAG)
switch action {
case "add-link":
err := e.InsertNodeAtPath(s.ctx, insertpath, nnode, nil)
if err != nil {
return "", err
}
_, err = e.Finalize(s.node.DAG)
if err != nil {
return "", err
}
final, err := e.GetNode().Key()
if err != nil {
return "", err
}
return final.B58String(), nil
default:
return "", fmt.Errorf("unsupported action (impl not complete)")
}
}
示例2: Pin
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
dagnodes := make([]node.Node, 0)
for _, fpath := range paths {
p, err := path.ParsePath(fpath)
if err != nil {
return nil, err
}
dagnode, err := core.Resolve(ctx, n.Namesys, n.Resolver, p)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
dagnodes = append(dagnodes, dagnode)
}
var out []*cid.Cid
for _, dagnode := range dagnodes {
c := dagnode.Cid()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
err := n.Pinning.Pin(ctx, dagnode, recursive)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
out = append(out, c)
}
err := n.Pinning.Flush()
if err != nil {
return nil, err
}
return out, nil
}
示例3: Unpin
func Unpin(n *core.IpfsNode, paths []string, recursive bool) ([]key.Key, error) {
// TODO(cryptix): do we want a ctx as first param for (Un)Pin() as well, just like core.Resolve?
ctx := n.Context()
dagnodes := make([]*merkledag.Node, 0)
for _, fpath := range paths {
dagnode, err := core.Resolve(ctx, n, path.Path(fpath))
if err != nil {
return nil, err
}
dagnodes = append(dagnodes, dagnode)
}
var unpinned []key.Key
for _, dagnode := range dagnodes {
k, _ := dagnode.Key()
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
err := n.Pinning.Unpin(ctx, k, recursive)
if err != nil {
return nil, err
}
unpinned = append(unpinned, k)
}
err := n.Pinning.Flush()
if err != nil {
return nil, err
}
return unpinned, nil
}
示例4: publish
func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.Path, opts *publishOpts) (*IpnsEntry, error) {
if opts.verifyExists {
// verify the path exists
_, err := core.Resolve(ctx, n.Namesys, n.Resolver, ref)
if err != nil {
return nil, err
}
}
eol := time.Now().Add(opts.pubValidTime)
err := n.Namesys.PublishWithEOL(ctx, k, ref, eol)
if err != nil {
return nil, err
}
pid, err := peer.IDFromPrivateKey(k)
if err != nil {
return nil, err
}
return &IpnsEntry{
Name: pid.Pretty(),
Value: ref.String(),
}, nil
}
示例5: Unpin
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]key.Key, error) {
dagnodes := make([]*merkledag.Node, 0)
for _, fpath := range paths {
dagnode, err := core.Resolve(ctx, n, path.Path(fpath))
if err != nil {
return nil, err
}
dagnodes = append(dagnodes, dagnode)
}
var unpinned []key.Key
for _, dagnode := range dagnodes {
k, _ := dagnode.Key()
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
err := n.Pinning.Unpin(ctx, k, recursive)
if err != nil {
return nil, err
}
unpinned = append(unpinned, k)
}
err := n.Pinning.Flush()
if err != nil {
return nil, err
}
return unpinned, nil
}
示例6: getNodeFromPath
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (node.Node, error) {
switch {
case strings.HasPrefix(p, "/ipfs/"):
np, err := path.ParsePath(p)
if err != nil {
return nil, err
}
resolver := &path.Resolver{
DAG: node.DAG,
ResolveOnce: uio.ResolveUnixfsOnce,
}
nd, err := core.Resolve(ctx, node.Namesys, resolver, np)
if err != nil {
return nil, err
}
pbnd, ok := nd.(*dag.ProtoNode)
if !ok {
return nil, dag.ErrNotProtobuf
}
return pbnd, nil
default:
fsn, err := mfs.Lookup(node.FilesRoot, p)
if err != nil {
return nil, err
}
return fsn.GetNode()
}
}
示例7: loadRoot
func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string) (fs.Node, error) {
p, err := path.ParsePath("/ipns/" + name)
if err != nil {
log.Errorf("mkpath %s: %s", name, err)
return nil, err
}
node, err := core.Resolve(ctx, ipfs, p)
if err != nil {
log.Errorf("looking up %s: %s", p, err)
return nil, err
}
root, err := mfs.NewRoot(ctx, ipfs.DAG, node, ipnsPubFunc(ipfs, rt.k))
if err != nil {
return nil, err
}
rt.root = root
switch val := root.GetValue().(type) {
case *mfs.Directory:
return &Directory{dir: val}, nil
case *mfs.File:
return &FileNode{fi: val}, nil
default:
return nil, errors.New("unrecognized type")
}
panic("not reached")
}
示例8: publish
func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.Path, opts *publishOpts) (*IpnsEntry, error) {
if opts.verifyExists {
// verify the path exists
_, err := core.Resolve(ctx, n, ref)
if err != nil {
return nil, err
}
}
eol := time.Now().Add(opts.pubValidTime)
err := n.Namesys.PublishWithEOL(ctx, k, ref, eol)
if err != nil {
return nil, err
}
hash, err := k.GetPublic().Hash()
if err != nil {
return nil, err
}
return &IpnsEntry{
Name: key.Key(hash).String(),
Value: ref.String(),
}, nil
}
示例9: Cat
func Cat(ctx context.Context, n *core.IpfsNode, pstr string) (*uio.DagReader, error) {
dagNode, err := core.Resolve(ctx, n, path.Path(pstr))
if err != nil {
return nil, err
}
return uio.NewDagReader(ctx, dagNode, n.DAG)
}
示例10: getZip
// getZip is equivalent to `ipfs getdag $hash | gzip`
func getZip(ctx context.Context, node *core.IpfsNode, p path.Path, compression int) (io.Reader, error) {
dagnode, err := core.Resolve(ctx, node, p)
if err != nil {
return nil, err
}
reader, err := uio.NewDagReader(ctx, dagnode, node.DAG)
if err != nil {
return nil, err
}
pr, pw := io.Pipe()
gw, err := gzip.NewWriterLevel(pw, compression)
if err != nil {
return nil, err
}
bufin := bufio.NewReader(reader)
go func() {
_, err := bufin.WriteTo(gw)
if err != nil {
log.Error("Fail to compress the stream")
}
gw.Close()
pw.Close()
}()
return pr, nil
}
示例11: Pin
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]key.Key, error) {
dagnodes := make([]*merkledag.Node, 0)
for _, fpath := range paths {
dagnode, err := core.Resolve(ctx, n, path.Path(fpath))
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
dagnodes = append(dagnodes, dagnode)
}
var out []key.Key
for _, dagnode := range dagnodes {
k, err := dagnode.Key()
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
err = n.Pinning.Pin(ctx, dagnode, recursive)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
out = append(out, k)
}
err := n.Pinning.Flush()
if err != nil {
return nil, err
}
return out, nil
}
示例12: get
func get(ctx context.Context, node *core.IpfsNode, p path.Path, compression int) (io.Reader, error) {
dagnode, err := core.Resolve(ctx, node, p)
if err != nil {
return nil, err
}
return utar.NewReader(ctx, p, node.DAG, dagnode, compression)
}
示例13: TestResolveNoComponents
func TestResolveNoComponents(t *testing.T) {
n, err := coremock.NewMockNode()
if n == nil || err != nil {
t.Fatal("Should have constructed a mock node", err)
}
_, err = core.Resolve(n.Context(), n, path.Path("/ipns/"))
if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipns/).", err)
}
_, err = core.Resolve(n.Context(), n, path.Path("/ipfs/"))
if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipfs/).", err)
}
}
示例14: get
func get(ctx context.Context, node *core.IpfsNode, p string, compression int) (io.Reader, error) {
pathToResolve := path.Path(p)
dagnode, err := core.Resolve(ctx, node, pathToResolve)
if err != nil {
return nil, err
}
return utar.NewReader(pathToResolve, node.DAG, dagnode, compression)
}
示例15: objectsForPaths
func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]*dag.Node, error) {
objects := make([]*dag.Node, len(paths))
for i, p := range paths {
o, err := core.Resolve(ctx, n, path.Path(p))
if err != nil {
return nil, err
}
objects[i] = o
}
return objects, nil
}