• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang core.Resolve函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ipfs/go-ipfs/core.Resolve函数的典型用法代码示例。如果您正苦于以下问题:Golang Resolve函数的具体用法?Golang Resolve怎么用?Golang Resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Resolve函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)")
	}
}
开发者ID:whyrusleeping,项目名称:ipfs-embedded-shell,代码行数:49,代码来源:object.go


示例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
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:35,代码来源:pinning.go


示例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
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:32,代码来源:pinning.go


示例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
}
开发者ID:VictorBjelkholm,项目名称:go-ipfs,代码行数:26,代码来源:publish.go


示例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
}
开发者ID:hebelken,项目名称:go-ipfs,代码行数:30,代码来源:pinning.go


示例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()
	}
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:32,代码来源:files.go


示例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")
}
开发者ID:palkeo,项目名称:go-ipfs,代码行数:31,代码来源:ipns_unix.go


示例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
}
开发者ID:kalmi,项目名称:go-ipfs,代码行数:26,代码来源:publish.go


示例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)
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:7,代码来源:cat.go


示例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
}
开发者ID:shuanzi,项目名称:go-ipfs,代码行数:29,代码来源:get.go


示例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
}
开发者ID:hebelken,项目名称:go-ipfs,代码行数:33,代码来源:pinning.go


示例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)
}
开发者ID:shuanzi,项目名称:go-ipfs,代码行数:8,代码来源:get.go


示例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)
	}

}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:17,代码来源:pathresolver_test.go


示例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)
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:9,代码来源:get.go


示例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
}
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:11,代码来源:refs.go


示例16: PatchLink

//TODO: hrm, maybe this interface could be better
func (s *Shell) PatchLink(root, npath, childhash string, create bool) (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
	}

	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)
	err = e.InsertNodeAtPath(s.ctx, npath, nnode, func() *dag.Node {
		return &dag.Node{Data: ft.FolderPBData()}
	})
	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
}
开发者ID:whyrusleeping,项目名称:ipfs-embedded-shell,代码行数:42,代码来源:object.go


示例17: ResolvePath

func (s *Shell) ResolvePath(ipath string) (string, error) {
	p, err := path.ParsePath(ipath)
	if err != nil {
		return "", err
	}

	nd, err := core.Resolve(s.ctx, s.node, p)
	if err != nil {
		return "", err
	}

	return nd.Key().B58String(), nil
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:13,代码来源:list.go


示例18: cat

func cat(ctx context.Context, node *core.IpfsNode, fpath string) (io.Reader, uint64, error) {
	dagnode, err := core.Resolve(ctx, node, path.Path(fpath))
	if err != nil {
		return nil, 0, err
	}

	reader, err := uio.NewDagReader(ctx, dagnode, node.DAG)
	if err != nil {
		return nil, 0, err
	}
	length := uint64(reader.Size())

	return reader, length, nil
}
开发者ID:cryptix,项目名称:ipget,代码行数:14,代码来源:main.go


示例19: resolve

func resolve(ctx context.Context, n *core.IpfsNode, p string) (ipld.Node, error) {
	pp, err := path.ParsePath(p)
	if err != nil {
		return nil, err
	}

	dagnode, err := core.Resolve(ctx, n.Namesys, n.Resolver, pp)
	if err == core.ErrNoNamesys {
		return nil, coreiface.ErrOffline
	} else if err != nil {
		return nil, err
	}
	return dagnode, nil
}
开发者ID:VictorBjelkholm,项目名称:go-ipfs,代码行数:14,代码来源:coreapi.go


示例20: Cat

// Cat resolves the ipfs path p and returns a reader for that data, if it exists and is availalbe
func (s *Shell) Cat(p string) (io.ReadCloser, error) {
	ipfsPath, err := path.ParsePath(p)
	if err != nil {
		return nil, errgo.Notef(err, "cat: could not parse %q", p)
	}
	nd, err := core.Resolve(s.ctx, s.node, ipfsPath)
	if err != nil {
		return nil, errgo.Notef(err, "cat: could not resolve %s", ipfsPath)
	}
	dr, err := unixfsio.NewDagReader(s.ctx, nd, s.node.DAG)
	if err != nil {
		return nil, errgo.Notef(err, "cat: failed to construct DAG reader")
	}
	return dr, nil
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:16,代码来源:cat.go



注:本文中的github.com/ipfs/go-ipfs/core.Resolve函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.IpfsNode类代码示例发布时间:2022-05-23
下一篇:
Golang core.NewNode函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap