当前位置: 首页>>代码示例>>Golang>>正文


Golang core.Resolve函数代码示例

本文整理汇总了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)")
	}
}
开发者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


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