Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
fc8d2258
提交
fc8d2258
authored
5月 10, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1219 from ipfs/refactor/httpGateway-quickfix
Refactor/http gateway quickfix (1191)
上级
d6fc414b
87ce7abe
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
120 行删除
+81
-120
gateway_handler.go
core/corehttp/gateway_handler.go
+71
-118
dirbuilder.go
unixfs/io/dirbuilder.go
+10
-2
没有找到文件。
core/corehttp/gateway_handler.go
浏览文件 @
fc8d2258
...
...
@@ -19,23 +19,15 @@ import (
dag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
"github.com/ipfs/go-ipfs/routing"
ufs
"github.com/ipfs/go-ipfs/unixfs"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
u
"github.com/ipfs/go-ipfs/util"
)
const
(
I
pfsPathPrefix
=
"/ipfs/"
I
pnsPathPrefix
=
"/ipns/"
i
pfsPathPrefix
=
"/ipfs/"
i
pnsPathPrefix
=
"/ipns/"
)
type
gateway
interface
{
ResolvePath
(
string
)
(
*
dag
.
Node
,
error
)
NewDagFromReader
(
io
.
Reader
)
(
*
dag
.
Node
,
error
)
AddNodeToDAG
(
nd
*
dag
.
Node
)
(
u
.
Key
,
error
)
NewDagReader
(
nd
*
dag
.
Node
)
(
uio
.
ReadSeekCloser
,
error
)
}
// shortcut for templating
type
webHandler
map
[
string
]
interface
{}
...
...
@@ -76,80 +68,31 @@ func (i *gatewayHandler) loadTemplate() error {
return
nil
}
func
(
i
*
gatewayHandler
)
resolveNamePath
(
ctx
context
.
Context
,
p
string
)
(
string
,
error
)
{
p
=
gopath
.
Clean
(
p
)
if
strings
.
HasPrefix
(
p
,
IpnsPathPrefix
)
{
elements
:=
strings
.
Split
(
p
[
len
(
IpnsPathPrefix
)
:
],
"/"
)
hash
:=
elements
[
0
]
rp
,
err
:=
i
.
node
.
Namesys
.
Resolve
(
ctx
,
hash
)
if
err
!=
nil
{
return
""
,
err
}
elements
=
append
(
rp
.
Segments
(),
elements
[
1
:
]
...
)
p
=
gopath
.
Join
(
elements
...
)
}
if
!
strings
.
HasPrefix
(
p
,
IpfsPathPrefix
)
{
p
=
gopath
.
Join
(
IpfsPathPrefix
,
p
)
}
return
p
,
nil
}
func
(
i
*
gatewayHandler
)
ResolvePath
(
ctx
context
.
Context
,
p
string
)
(
*
dag
.
Node
,
string
,
error
)
{
p
,
err
:=
i
.
resolveNamePath
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
""
,
err
}
node
,
err
:=
i
.
node
.
Resolver
.
ResolvePath
(
ctx
,
path
.
Path
(
p
))
if
err
!=
nil
{
return
nil
,
""
,
err
}
return
node
,
p
,
err
}
func
(
i
*
gatewayHandler
)
NewDagFromReader
(
r
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
// TODO(cryptix): find these helpers somewhere else
func
(
i
*
gatewayHandler
)
newDagFromReader
(
r
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
// TODO(cryptix): change and remove this helper once PR1136 is merged
// return ufs.AddFromReader(i.node, r.Body)
return
importer
.
BuildDagFromReader
(
r
,
i
.
node
.
DAG
,
i
.
node
.
Pinning
.
GetManual
(),
chunk
.
DefaultSplitter
)
}
func
NewDagEmptyDir
()
*
dag
.
Node
{
return
&
dag
.
Node
{
Data
:
ufs
.
FolderPBData
()}
}
func
(
i
*
gatewayHandler
)
AddNodeToDAG
(
nd
*
dag
.
Node
)
(
u
.
Key
,
error
)
{
return
i
.
node
.
DAG
.
Add
(
nd
)
}
func
(
i
*
gatewayHandler
)
NewDagReader
(
nd
*
dag
.
Node
)
(
uio
.
ReadSeekCloser
,
error
)
{
return
uio
.
NewDagReader
(
i
.
node
.
Context
(),
nd
,
i
.
node
.
DAG
)
}
// TODO(btc): break this apart into separate handlers using a more expressive
// muxer
// TODO(btc): break this apart into separate handlers using a more expressive muxer
func
(
i
*
gatewayHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
i
.
config
.
Writable
&&
r
.
Method
==
"POST"
{
i
.
postHandler
(
w
,
r
)
return
}
if
i
.
config
.
Writable
&&
r
.
Method
==
"PUT"
{
i
.
putHandler
(
w
,
r
)
return
}
if
i
.
config
.
Writable
&&
r
.
Method
==
"DELETE"
{
i
.
deleteHandler
(
w
,
r
)
return
}
if
r
.
Method
==
"GET"
{
i
.
getOrHeadHandler
(
w
,
r
)
return
if
i
.
config
.
Writable
{
switch
r
.
Method
{
case
"POST"
:
i
.
postHandler
(
w
,
r
)
return
case
"PUT"
:
i
.
putHandler
(
w
,
r
)
return
case
"DELETE"
:
i
.
deleteHandler
(
w
,
r
)
return
}
}
if
r
.
Method
==
"HEAD"
{
if
r
.
Method
==
"
GET"
||
r
.
Method
==
"
HEAD"
{
i
.
getOrHeadHandler
(
w
,
r
)
return
}
...
...
@@ -162,8 +105,8 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w
.
WriteHeader
(
http
.
StatusBadRequest
)
errmsg
=
errmsg
+
"bad request for "
+
r
.
URL
.
Path
}
w
.
Write
([]
byte
(
errmsg
)
)
log
.
Debug
(
errmsg
)
fmt
.
Fprint
(
w
,
errmsg
)
log
.
Error
(
errmsg
)
// TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe
)
}
func
(
i
*
gatewayHandler
)
getOrHeadHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -178,19 +121,19 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
return
}
nd
,
p
,
err
:=
i
.
ResolvePath
(
ctx
,
urlPath
)
nd
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
)
)
if
err
!=
nil
{
webError
(
w
,
"Path Resolve error"
,
err
,
http
.
StatusBadRequest
)
return
}
etag
:=
gopath
.
Base
(
p
)
etag
:=
gopath
.
Base
(
urlPath
)
if
r
.
Header
.
Get
(
"If-None-Match"
)
==
etag
{
w
.
WriteHeader
(
http
.
StatusNotModified
)
return
}
w
.
Header
()
.
Set
(
"X-IPFS-Path"
,
p
)
w
.
Header
()
.
Set
(
"X-IPFS-Path"
,
urlPath
)
// Suborigin header, sandboxes apps from each other in the browser (even
// though they are served from the same gateway domain). NOTE: This is not
...
...
@@ -198,7 +141,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
pathRoot
:=
strings
.
SplitN
(
urlPath
,
"/"
,
4
)[
2
]
w
.
Header
()
.
Set
(
"Suborigin"
,
pathRoot
)
dr
,
err
:=
i
.
NewDagReader
(
nd
)
dr
,
err
:=
uio
.
NewDagReader
(
ctx
,
nd
,
i
.
node
.
DAG
)
if
err
!=
nil
&&
err
!=
uio
.
ErrIsDir
{
// not a directory and still an error
internalWebError
(
w
,
err
)
...
...
@@ -210,7 +153,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
// and only if it's /ipfs!
// TODO: break this out when we split /ipfs /ipns routes.
modtime
:=
time
.
Now
()
if
strings
.
HasPrefix
(
urlPath
,
I
pfsPathPrefix
)
{
if
strings
.
HasPrefix
(
urlPath
,
i
pfsPathPrefix
)
{
w
.
Header
()
.
Set
(
"Etag"
,
etag
)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"public, max-age=29030400"
)
...
...
@@ -239,12 +182,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
log
.
Debug
(
"found index"
)
foundIndex
=
true
// return index page instead.
nd
,
_
,
err
:=
i
.
ResolvePath
(
ctx
,
urlPath
+
"/index.html"
)
nd
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
+
"/index.html"
)
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
dr
,
err
:=
i
.
NewDagReader
(
nd
)
dr
,
err
:=
uio
.
NewDagReader
(
ctx
,
nd
,
i
.
node
.
DAG
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -279,13 +222,13 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
}
func
(
i
*
gatewayHandler
)
postHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
nd
,
err
:=
i
.
N
ewDagFromReader
(
r
.
Body
)
nd
,
err
:=
i
.
n
ewDagFromReader
(
r
.
Body
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
k
,
err
:=
i
.
AddNodeToDAG
(
nd
)
k
,
err
:=
i
.
node
.
DAG
.
Add
(
nd
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -293,11 +236,11 @@ func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) {
h
:=
mh
.
Multihash
(
k
)
.
B58String
()
w
.
Header
()
.
Set
(
"IPFS-Hash"
,
h
)
http
.
Redirect
(
w
,
r
,
I
pfsPathPrefix
+
h
,
http
.
StatusCreated
)
http
.
Redirect
(
w
,
r
,
i
pfsPathPrefix
+
h
,
http
.
StatusCreated
)
}
func
(
i
*
gatewayHandler
)
putEmptyDirHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
newnode
:=
NewDagEmptyDir
()
newnode
:=
uio
.
NewEmptyDirectory
()
key
,
err
:=
i
.
node
.
DAG
.
Add
(
newnode
)
if
err
!=
nil
{
...
...
@@ -306,7 +249,7 @@ func (i *gatewayHandler) putEmptyDirHandler(w http.ResponseWriter, r *http.Reque
}
w
.
Header
()
.
Set
(
"IPFS-Hash"
,
key
.
String
())
http
.
Redirect
(
w
,
r
,
I
pfsPathPrefix
+
key
.
String
()
+
"/"
,
http
.
StatusCreated
)
http
.
Redirect
(
w
,
r
,
i
pfsPathPrefix
+
key
.
String
()
+
"/"
,
http
.
StatusCreated
)
}
func
(
i
*
gatewayHandler
)
putHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -316,16 +259,16 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
urlPath
:=
r
.
URL
.
Path
pathext
:=
urlPath
[
5
:
]
var
err
error
if
urlPath
==
I
pfsPathPrefix
+
"QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/"
{
if
urlPath
==
i
pfsPathPrefix
+
"QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/"
{
i
.
putEmptyDirHandler
(
w
,
r
)
return
}
var
newnode
*
dag
.
Node
if
pathext
[
len
(
pathext
)
-
1
]
==
'/'
{
newnode
=
NewDagEmptyDir
()
newnode
=
uio
.
NewEmptyDirectory
()
}
else
{
newnode
,
err
=
i
.
N
ewDagFromReader
(
r
.
Body
)
newnode
,
err
=
i
.
n
ewDagFromReader
(
r
.
Body
)
if
err
!=
nil
{
webError
(
w
,
"Could not create DAG from request"
,
err
,
http
.
StatusInternalServerError
)
return
...
...
@@ -335,14 +278,20 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
ctx
,
cancel
:=
context
.
WithCancel
(
i
.
node
.
Context
())
defer
cancel
()
ipfs
path
,
err
:=
i
.
resolveNamePath
(
ctx
,
urlPath
)
ipfs
Node
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
)
)
if
err
!=
nil
{
// FIXME HTTP error code
webError
(
w
,
"Could not resolve name"
,
err
,
http
.
StatusInternalServerError
)
return
}
h
,
components
,
err
:=
path
.
SplitAbsPath
(
path
.
Path
(
ipfspath
))
k
,
err
:=
ipfsNode
.
Key
()
if
err
!=
nil
{
webError
(
w
,
"Could not get key from resolved node"
,
err
,
http
.
StatusInternalServerError
)
return
}
h
,
components
,
err
:=
path
.
SplitAbsPath
(
path
.
FromKey
(
k
))
if
err
!=
nil
{
webError
(
w
,
"Could not split path"
,
err
,
http
.
StatusInternalServerError
)
return
...
...
@@ -350,14 +299,13 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
if
len
(
components
)
<
1
{
err
=
fmt
.
Errorf
(
"Cannot override existing object"
)
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
err
.
Error
()))
log
.
Debug
(
"%s"
,
err
)
webError
(
w
,
"http gateway"
,
err
,
http
.
StatusBadRequest
)
return
}
tctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Minute
)
defer
cancel
()
// TODO(cryptix): could this be core.Resolve() too?
rootnd
,
err
:=
i
.
node
.
Resolver
.
DAG
.
Get
(
tctx
,
u
.
Key
(
h
))
if
err
!=
nil
{
webError
(
w
,
"Could not resolve root object"
,
err
,
http
.
StatusBadRequest
)
...
...
@@ -366,19 +314,19 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
// resolving path components into merkledag nodes. if a component does not
// resolve, create empty directories (which will be linked and populated below.)
path
_n
odes
,
err
:=
i
.
node
.
Resolver
.
ResolveLinks
(
tctx
,
rootnd
,
components
[
:
len
(
components
)
-
1
])
path
N
odes
,
err
:=
i
.
node
.
Resolver
.
ResolveLinks
(
tctx
,
rootnd
,
components
[
:
len
(
components
)
-
1
])
if
_
,
ok
:=
err
.
(
path
.
ErrNoLink
);
ok
{
// Create empty directories, links will be made further down the code
for
len
(
path
_n
odes
)
<
len
(
components
)
{
path
_nodes
=
append
(
path_nodes
,
NewDagEmptyDir
())
for
len
(
path
N
odes
)
<
len
(
components
)
{
path
Nodes
=
append
(
pathNodes
,
uio
.
NewDirectory
(
i
.
node
.
DAG
)
.
GetNode
())
}
}
else
if
err
!=
nil
{
webError
(
w
,
"Could not resolve parent object"
,
err
,
http
.
StatusBadRequest
)
return
}
for
i
:=
len
(
path
_n
odes
)
-
1
;
i
>=
0
;
i
--
{
newnode
,
err
=
path
_n
odes
[
i
]
.
UpdateNodeLink
(
components
[
i
],
newnode
)
for
i
:=
len
(
path
N
odes
)
-
1
;
i
>=
0
;
i
--
{
newnode
,
err
=
path
N
odes
[
i
]
.
UpdateNodeLink
(
components
[
i
],
newnode
)
if
err
!=
nil
{
webError
(
w
,
"Could not update node links"
,
err
,
http
.
StatusInternalServerError
)
return
...
...
@@ -399,7 +347,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
}
w
.
Header
()
.
Set
(
"IPFS-Hash"
,
key
.
String
())
http
.
Redirect
(
w
,
r
,
I
pfsPathPrefix
+
key
.
String
()
+
"/"
+
strings
.
Join
(
components
,
"/"
),
http
.
StatusCreated
)
http
.
Redirect
(
w
,
r
,
i
pfsPathPrefix
+
key
.
String
()
+
"/"
+
strings
.
Join
(
components
,
"/"
),
http
.
StatusCreated
)
}
func
(
i
*
gatewayHandler
)
deleteHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -407,14 +355,20 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
ctx
,
cancel
:=
context
.
WithCancel
(
i
.
node
.
Context
())
defer
cancel
()
ipfs
path
,
err
:=
i
.
resolveNamePath
(
ctx
,
urlPath
)
ipfs
Node
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
)
)
if
err
!=
nil
{
// FIXME HTTP error code
webError
(
w
,
"Could not resolve name"
,
err
,
http
.
StatusInternalServerError
)
return
}
h
,
components
,
err
:=
path
.
SplitAbsPath
(
path
.
Path
(
ipfspath
))
k
,
err
:=
ipfsNode
.
Key
()
if
err
!=
nil
{
webError
(
w
,
"Could not get key from resolved node"
,
err
,
http
.
StatusInternalServerError
)
return
}
h
,
components
,
err
:=
path
.
SplitAbsPath
(
path
.
FromKey
(
k
))
if
err
!=
nil
{
webError
(
w
,
"Could not split path"
,
err
,
http
.
StatusInternalServerError
)
return
...
...
@@ -428,21 +382,22 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
return
}
path
_n
odes
,
err
:=
i
.
node
.
Resolver
.
ResolveLinks
(
tctx
,
rootnd
,
components
[
:
len
(
components
)
-
1
])
path
N
odes
,
err
:=
i
.
node
.
Resolver
.
ResolveLinks
(
tctx
,
rootnd
,
components
[
:
len
(
components
)
-
1
])
if
err
!=
nil
{
webError
(
w
,
"Could not resolve parent object"
,
err
,
http
.
StatusBadRequest
)
return
}
err
=
path_nodes
[
len
(
path_nodes
)
-
1
]
.
RemoveNodeLink
(
components
[
len
(
components
)
-
1
])
// TODO(cyrptix): assumes len(pathNodes) > 1 - not found is an error above?
err
=
pathNodes
[
len
(
pathNodes
)
-
1
]
.
RemoveNodeLink
(
components
[
len
(
components
)
-
1
])
if
err
!=
nil
{
webError
(
w
,
"Could not delete link"
,
err
,
http
.
StatusBadRequest
)
return
}
newnode
:=
path
_nodes
[
len
(
path_n
odes
)
-
1
]
for
i
:=
len
(
path
_n
odes
)
-
2
;
i
>=
0
;
i
--
{
newnode
,
err
=
path
_n
odes
[
i
]
.
UpdateNodeLink
(
components
[
i
],
newnode
)
newnode
:=
path
Nodes
[
len
(
pathN
odes
)
-
1
]
for
i
:=
len
(
path
N
odes
)
-
2
;
i
>=
0
;
i
--
{
newnode
,
err
=
path
N
odes
[
i
]
.
UpdateNodeLink
(
components
[
i
],
newnode
)
if
err
!=
nil
{
webError
(
w
,
"Could not update node links"
,
err
,
http
.
StatusInternalServerError
)
return
...
...
@@ -463,7 +418,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
}
w
.
Header
()
.
Set
(
"IPFS-Hash"
,
key
.
String
())
http
.
Redirect
(
w
,
r
,
I
pfsPathPrefix
+
key
.
String
()
+
"/"
+
strings
.
Join
(
components
[
:
len
(
components
)
-
1
],
"/"
),
http
.
StatusCreated
)
http
.
Redirect
(
w
,
r
,
i
pfsPathPrefix
+
key
.
String
()
+
"/"
+
strings
.
Join
(
components
[
:
len
(
components
)
-
1
],
"/"
),
http
.
StatusCreated
)
}
func
webError
(
w
http
.
ResponseWriter
,
message
string
,
err
error
,
defaultCode
int
)
{
...
...
@@ -480,15 +435,13 @@ func webError(w http.ResponseWriter, message string, err error, defaultCode int)
func
webErrorWithCode
(
w
http
.
ResponseWriter
,
message
string
,
err
error
,
code
int
)
{
w
.
WriteHeader
(
code
)
log
.
Debugf
(
"%s: %s"
,
message
,
err
)
w
.
Write
([]
byte
(
message
+
": "
+
err
.
Error
())
)
log
.
Errorf
(
"%s: %s"
,
message
,
err
)
// TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe
)
fmt
.
Fprintf
(
w
,
"%s: %s"
,
message
,
err
)
}
// return a 500 error and log
func
internalWebError
(
w
http
.
ResponseWriter
,
err
error
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
w
.
Write
([]
byte
(
err
.
Error
()))
log
.
Debug
(
"%s"
,
err
)
webErrorWithCode
(
w
,
"internalWebError"
,
err
,
http
.
StatusInternalServerError
)
}
// Directory listing template
...
...
unixfs/io/dirbuilder.go
浏览文件 @
fc8d2258
...
...
@@ -15,15 +15,22 @@ type directoryBuilder struct {
dirnode
*
mdag
.
Node
}
// NewEmptyDirectory returns an empty merkledag Node with a folder Data chunk
func
NewEmptyDirectory
()
*
mdag
.
Node
{
return
&
mdag
.
Node
{
Data
:
format
.
FolderPBData
()}
}
// NewDirectory returns a directoryBuilder. It needs a DAGService to add the Children
func
NewDirectory
(
dserv
mdag
.
DAGService
)
*
directoryBuilder
{
db
:=
new
(
directoryBuilder
)
db
.
dserv
=
dserv
db
.
dirnode
=
new
(
mdag
.
Node
)
db
.
dirnode
.
Data
=
format
.
FolderPBData
()
db
.
dirnode
=
NewEmptyDirectory
()
return
db
}
// AddChild adds a (name, key)-pair to the root node.
func
(
d
*
directoryBuilder
)
AddChild
(
name
string
,
k
u
.
Key
)
error
{
// TODO(cryptix): consolidate context managment
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Minute
)
defer
cancel
()
...
...
@@ -40,6 +47,7 @@ func (d *directoryBuilder) AddChild(name string, k u.Key) error {
return
nil
}
// GetNode returns the root of this directoryBuilder
func
(
d
*
directoryBuilder
)
GetNode
()
*
mdag
.
Node
{
return
d
.
dirnode
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论