本文整理汇总了Golang中github.com/ipfs/go-ipfs/mfs.Lookup函数的典型用法代码示例。如果您正苦于以下问题:Golang Lookup函数的具体用法?Golang Lookup怎么用?Golang Lookup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lookup函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getFileHandle
func getFileHandle(r *mfs.Root, path string, create bool) (*mfs.File, error) {
target, err := mfs.Lookup(r, path)
switch err {
case nil:
fi, ok := target.(*mfs.File)
if !ok {
return nil, fmt.Errorf("%s was not a file", path)
}
return fi, nil
case os.ErrNotExist:
if !create {
return nil, err
}
// if create is specified and the file doesnt exist, we create the file
dirname, fname := gopath.Split(path)
pdiri, err := mfs.Lookup(r, dirname)
if err != nil {
log.Error("lookupfail ", dirname)
return nil, err
}
pdir, ok := pdiri.(*mfs.Directory)
if !ok {
return nil, fmt.Errorf("%s was not a directory", dirname)
}
nd := dag.NodeWithData(ft.FilePBData(nil, 0))
err = pdir.AddChild(fname, nd)
if err != nil {
return nil, err
}
fsn, err := pdir.Child(fname)
if err != nil {
return nil, err
}
fi, ok := fsn.(*mfs.File)
if !ok {
return nil, errors.New("Expected *mfs.File, didnt get it. This is likely a race condition.")
}
return fi, nil
default:
return nil, err
}
}
示例2: 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()
}
}
示例3: getNodeFromPath
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (*dag.Node, error) {
switch {
case strings.HasPrefix(p, "/ipfs/"):
np, err := path.ParsePath(p)
if err != nil {
return nil, err
}
return core.Resolve(ctx, node, np)
default:
fsn, err := mfs.Lookup(node.FilesRoot, p)
if err != nil {
return nil, err
}
return fsn.GetNode()
}
}
示例4:
res.SetError(err, cmds.ErrClient)
}
node, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
path, err := checkPath(req.Arguments()[0])
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
fsn, err := mfs.Lookup(node.FilesRoot, path)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
o, err := statNode(node.DAG, fsn)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(o)
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {