本文整理汇总了Golang中github.com/ipfs/go-ipfs/path.ParsePath函数的典型用法代码示例。如果您正苦于以下问题:Golang ParsePath函数的具体用法?Golang ParsePath怎么用?Golang ParsePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParsePath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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/")
}
开发者ID:yiwang,项目名称:go-ipfs,代码行数:12,代码来源:namesys.go
示例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)")
}
}
开发者ID:whyrusleeping,项目名称:ipfs-embedded-shell,代码行数:49,代码来源:object.go
示例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,
})
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:32,代码来源:namesys.go
示例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()
}
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:32,代码来源:files.go
示例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")
}
开发者ID:palkeo,项目名称:go-ipfs,代码行数:31,代码来源:ipns_unix.go
示例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
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:35,代码来源:pinning.go
示例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
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:29,代码来源:pinning.go
示例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")
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:8,代码来源:dns.go
示例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
}
开发者ID:whyrusleeping,项目名称:ipfs-embedded-shell,代码行数:42,代码来源:object.go
示例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
}
}
开发者ID:heems,项目名称:go-ipfs,代码行数:55,代码来源:routing.go
示例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
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:13,代码来源:list.go
示例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
}
开发者ID:VictorBjelkholm,项目名称:go-ipfs,代码行数:14,代码来源:coreapi.go
示例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)
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:15,代码来源:namesys_test.go
示例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
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:16,代码来源:cat.go
示例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
}
开发者ID:VictorBjelkholm,项目名称:go-ipfs,代码行数:16,代码来源:refs.go
示例16: 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()
}
}
开发者ID:yuanwr,项目名称:go-ipfs,代码行数:18,代码来源:files.go
示例17: pinLsKeys
func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) {
keys := make(map[string]RefKeyObject)
for _, p := range args {
pth, err := path.ParsePath(p)
if err != nil {
return nil, err
}
dagNode, err := core.Resolve(ctx, n.Namesys, n.Resolver, pth)
if err != nil {
return nil, err
}
mode, ok := pin.StringToPinMode(typeStr)
if !ok {
return nil, fmt.Errorf("Invalid pin mode '%s'", typeStr)
}
c := dagNode.Cid()
pinType, pinned, err := n.Pinning.IsPinnedWithType(c, mode)
if err != nil {
return nil, err
}
if !pinned {
return nil, fmt.Errorf("Path '%s' is not pinned", p)
}
switch pinType {
case "direct", "indirect", "recursive", "internal":
default:
pinType = "indirect through " + pinType
}
keys[c.String()] = RefKeyObject{
Type: pinType,
}
}
return keys, nil
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:42,代码来源:pin.go
示例18: Get
// Cat resolves the ipfs path p and returns a reader for that data, if it exists and is availalbe
func (s *Shell) Get(ref, outdir string) error {
ipfsPath, err := path.ParsePath(ref)
if err != nil {
return errgo.Notef(err, "get: could not parse %q", ref)
}
nd, err := core.Resolve(s.ctx, s.node, ipfsPath)
if err != nil {
return errgo.Notef(err, "get: could not resolve %s", ipfsPath)
}
r, err := uarchive.DagArchive(s.ctx, nd, outdir, s.node.DAG, false, 0)
if err != nil {
return err
}
ext := tar.Extractor{outdir}
return ext.Extract(r)
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:21,代码来源:get.go
示例19: List
func (s *Shell) List(ipath string) ([]*sh.LsLink, error) {
p, err := path.ParsePath(ipath)
if err != nil {
return nil, err
}
nd, err := core.Resolve(s.ctx, s.node, p)
if err != nil {
return nil, err
}
var out []*sh.LsLink
for _, l := range nd.Links {
out = append(out, &sh.LsLink{
Hash: l.Hash.B58String(),
Name: l.Name,
Size: l.Size,
})
}
return out, nil
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:22,代码来源:list.go
示例20:
cmds.StringArg("obj_b", true, false, "object to diff"),
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Produce verbose output"),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
a := req.Arguments()[0]
b := req.Arguments()[1]
pa, err := path.ParsePath(a)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
pb, err := path.ParsePath(b)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
ctx := req.Context()
obj_a, err := core.Resolve(ctx, node, pa)
if err != nil {
开发者ID:Kubuxu,项目名称:go-ipfs,代码行数:31,代码来源:diff.go
注:本文中的github.com/ipfs/go-ipfs/path.ParsePath函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论