提交 ff3447f0 作者: Jeromy

WIP: experiment in making protobuf nodes with no linknames resolvable

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 40533eda
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
...@@ -148,7 +149,11 @@ func (n *ProtoNode) RemoveNodeLink(name string) error { ...@@ -148,7 +149,11 @@ func (n *ProtoNode) RemoveNodeLink(name string) error {
// Return a copy of the link with given name // Return a copy of the link with given name
func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) { func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
allemptynames := true
for _, l := range n.links { for _, l := range n.links {
if allemptynames && l.Name != "" {
allemptynames = false
}
if l.Name == name { if l.Name == name {
return &node.Link{ return &node.Link{
Name: l.Name, Name: l.Name,
...@@ -157,6 +162,17 @@ func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) { ...@@ -157,6 +162,17 @@ func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
}, nil }, nil
} }
} }
if allemptynames {
ix, err := strconv.Atoi(name)
if err == nil && ix >= 0 && ix < len(n.links) {
l := n.links[ix]
return &node.Link{
Name: l.Name,
Size: l.Size,
Cid: l.Cid,
}, nil
}
}
return nil, ErrLinkNotFound return nil, ErrLinkNotFound
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论