本文整理汇总了Golang中gx/ipfs/QmU7bFWQ793qmvNy7outdCaMfSDNk8uqhx4VNrxYj5fj5g/go-ipld-node.Node.Links方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Links方法的具体用法?Golang Node.Links怎么用?Golang Node.Links使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gx/ipfs/QmU7bFWQ793qmvNy7outdCaMfSDNk8uqhx4VNrxYj5fj5g/go-ipld-node.Node
的用法示例。
在下文中一共展示了Node.Links方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeRefsRecursive
func (rw *RefWriter) writeRefsRecursive(n node.Node) (int, error) {
nc := n.Cid()
var count int
for i, ng := range dag.GetDAG(rw.Ctx, rw.DAG, n) {
lc := n.Links()[i].Cid
if rw.skip(lc) {
continue
}
if err := rw.WriteEdge(nc, lc, n.Links()[i].Name); err != nil {
return count, err
}
nd, err := ng.Get(rw.Ctx)
if err != nil {
return count, err
}
c, err := rw.writeRefsRecursive(nd)
count += c
if err != nil {
return count, err
}
}
return count, nil
}
示例2: GetDAG
// GetDAG will fill out all of the links of the given Node.
// It returns a channel of nodes, which the caller can receive
// all the child nodes of 'root' on, in proper order.
func GetDAG(ctx context.Context, ds DAGService, root node.Node) []NodeGetter {
var cids []*cid.Cid
for _, lnk := range root.Links() {
cids = append(cids, lnk.Cid)
}
return GetNodes(ctx, ds, cids)
}
示例3: getOutput
// from core/commands/object.go
func getOutput(dagnode node.Node) (*Object, error) {
c := dagnode.Cid()
output := &Object{
Hash: c.String(),
Links: make([]Link, len(dagnode.Links())),
}
for i, link := range dagnode.Links() {
output.Links[i] = Link{
Name: link.Name,
Size: link.Size,
}
}
return output, nil
}
示例4: NewDagReader
// NewDagReader creates a new reader object that reads the data represented by
// the given node, using the passed in DAGService for data retreival
func NewDagReader(ctx context.Context, n node.Node, serv mdag.DAGService) (*DagReader, error) {
switch n := n.(type) {
case *mdag.RawNode:
return &DagReader{
buf: NewRSNCFromBytes(n.RawData()),
}, nil
case *mdag.ProtoNode:
pb := new(ftpb.Data)
if err := proto.Unmarshal(n.Data(), pb); err != nil {
return nil, err
}
switch pb.GetType() {
case ftpb.Data_Directory:
// Dont allow reading directories
return nil, ErrIsDir
case ftpb.Data_File, ftpb.Data_Raw:
return NewDataFileReader(ctx, n, pb, serv), nil
case ftpb.Data_Metadata:
if len(n.Links()) == 0 {
return nil, errors.New("incorrectly formatted metadata object")
}
child, err := n.Links()[0].GetNode(ctx, serv)
if err != nil {
return nil, err
}
childpb, ok := child.(*mdag.ProtoNode)
if !ok {
return nil, mdag.ErrNotProtobuf
}
return NewDagReader(ctx, childpb, serv)
case ftpb.Data_Symlink:
return nil, ErrCantReadSymlinks
default:
return nil, ft.ErrUnrecognizedType
}
default:
return nil, fmt.Errorf("unrecognized node type")
}
}
示例5: writeRefsSingle
func (rw *RefWriter) writeRefsSingle(n node.Node) (int, error) {
c := n.Cid()
if rw.skip(c) {
return 0, nil
}
count := 0
for _, l := range n.Links() {
lc := l.Cid
if rw.skip(lc) {
continue
}
if err := rw.WriteEdge(c, lc, l.Name); err != nil {
return count, err
}
count++
}
return count, nil
}