本文整理汇总了Golang中github.com/ipfs/go-ipfs/path.ParsePath函数的典型用法代码示例。如果您正苦于以下问题:Golang ParsePath函数的具体用法?Golang ParsePath怎么用?Golang ParsePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParsePath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ResolveN
// ResolveN implements Resolver.
func (ns *mpns) ResolveN(ctx context.Context, name string, depth int) (path.Path, error) {
if strings.HasPrefix(name, "/ipfs/") {
return path.ParsePath(name)
}
if !strings.HasPrefix(name, "/") {
return path.ParsePath("/ipfs/" + name)
}
return resolve(ctx, ns, name, depth, "/ipns/")
}
示例2: 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)")
}
}
示例3: addToDHTCache
func (ns *mpns) addToDHTCache(key ci.PrivKey, value path.Path, eol time.Time) {
rr, ok := ns.resolvers["dht"].(*routingResolver)
if !ok {
// should never happen, purely for sanity
log.Panicf("unexpected type %T as DHT resolver.", ns.resolvers["dht"])
}
if rr.cache == nil {
// resolver has no caching
return
}
var err error
value, err = path.ParsePath(value.String())
if err != nil {
log.Error("could not parse path")
return
}
name, err := peer.IDFromPrivateKey(key)
if err != nil {
log.Error("while adding to cache, could not get peerid from private key")
return
}
if time.Now().Add(DefaultResolverCacheTTL).Before(eol) {
eol = time.Now().Add(DefaultResolverCacheTTL)
}
rr.cache.Add(name.Pretty(), cacheEntry{
val: value,
eol: eol,
})
}
示例4: 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()
}
}
示例5: 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")
}
示例6: 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
}
示例7: Unpin
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
var unpinned []*cid.Cid
for _, p := range paths {
p, err := path.ParsePath(p)
if err != nil {
return nil, err
}
k, err := core.ResolveToCid(ctx, n, p)
if err != nil {
return nil, err
}
ctx, cancel := context.WithCancel(ctx)
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
}
示例8: tryParseDnsLink
func tryParseDnsLink(txt string) (path.Path, error) {
parts := strings.SplitN(txt, "=", 2)
if len(parts) == 2 && parts[0] == "dnslink" {
return path.ParsePath(parts[1])
}
return "", errors.New("not a valid dnslink entry")
}
示例9: 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
}
示例10: resolveOnce
// resolveOnce implements resolver. Uses the IPFS routing system to
// resolve SFS-like names.
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
log.Debugf("RoutingResolve: '%s'", name)
hash, err := mh.FromB58String(name)
if err != nil {
log.Warning("RoutingResolve: bad input hash: [%s]\n", name)
return "", err
}
// name should be a multihash. if it isn't, error out here.
// use the routing system to get the name.
// /ipns/<name>
h := []byte("/ipns/" + string(hash))
ipnsKey := key.Key(h)
val, err := r.routing.GetValue(ctx, ipnsKey)
if err != nil {
log.Warning("RoutingResolve get failed.")
return "", err
}
entry := new(pb.IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
return "", err
}
// name should be a public key retrievable from ipfs
pubkey, err := routing.GetPublicKey(r.routing, ctx, hash)
if err != nil {
return "", err
}
hsh, _ := pubkey.Hash()
log.Debugf("pk hash = %s", key.Key(hsh))
// check sig with pk
if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok {
return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey)
}
// ok sig checks out. this is a valid name.
// check for old style record:
valh, err := mh.Cast(entry.GetValue())
if err != nil {
// Not a multihash, probably a new record
return path.ParsePath(string(entry.GetValue()))
} else {
// Its an old style multihash record
log.Warning("Detected old style multihash record")
return path.FromKey(key.Key(valh)), nil
}
}
示例11: 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
}
示例12: 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
}
示例13: TestPublishWithCache0
func TestPublishWithCache0(t *testing.T) {
dst := ds.NewMapDatastore()
priv, _, err := ci.GenerateKeyPair(ci.RSA, 1024)
if err != nil {
t.Fatal(err)
}
routing := offroute.NewOfflineRouter(dst, priv)
nsys := NewNameSystem(routing, dst, 0)
p, err := path.ParsePath(unixfs.EmptyDirNode().Cid().String())
if err != nil {
t.Fatal(err)
}
nsys.Publish(context.Background(), priv, p)
}
示例14: 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
}
示例15: objectsForPaths
func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]node.Node, error) {
objects := make([]node.Node, len(paths))
for i, sp := range paths {
p, err := path.ParsePath(sp)
if err != nil {
return nil, err
}
o, err := core.Resolve(ctx, n.Namesys, n.Resolver, p)
if err != nil {
return nil, err
}
objects[i] = o
}
return objects, nil
}