Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e260d2fd
提交
e260d2fd
authored
11月 16, 2016
作者:
Lars Gierth
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: smarter way of dealing with the different APIs
License: MIT Signed-off-by:
Lars Gierth
<
larsg@systemli.org
>
上级
6efa429a
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
26 行增加
和
22 行删除
+26
-22
coreapi.go
core/coreapi/coreapi.go
+13
-0
interface.go
core/coreapi/interface/interface.go
+4
-5
unixfs.go
core/coreapi/unixfs.go
+1
-9
unixfs_test.go
core/coreapi/unixfs_test.go
+1
-1
gateway.go
core/corehttp/gateway.go
+1
-1
gateway_handler.go
core/corehttp/gateway_handler.go
+6
-6
没有找到文件。
core/coreapi/coreapi.go
浏览文件 @
e260d2fd
...
...
@@ -10,6 +10,19 @@ import (
ipld
"gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
)
type
CoreAPI
struct
{
node
*
core
.
IpfsNode
}
func
NewCoreAPI
(
n
*
core
.
IpfsNode
)
coreiface
.
CoreAPI
{
api
:=
&
CoreAPI
{
n
}
return
api
}
func
(
api
*
CoreAPI
)
Unixfs
()
coreiface
.
UnixfsAPI
{
return
(
*
UnixfsAPI
)(
api
)
}
func
resolve
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
p
string
)
(
ipld
.
Node
,
error
)
{
pp
,
err
:=
path
.
ParsePath
(
p
)
if
err
!=
nil
{
...
...
core/coreapi/interface/interface.go
浏览文件 @
e260d2fd
...
...
@@ -9,11 +9,6 @@ import (
ipld
"gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
)
// type CoreAPI interface {
// ID() CoreID
// Version() CoreVersion
// }
type
Link
ipld
.
Link
type
Reader
interface
{
...
...
@@ -21,6 +16,10 @@ type Reader interface {
io
.
Closer
}
type
CoreAPI
interface
{
Unixfs
()
UnixfsAPI
}
type
UnixfsAPI
interface
{
Add
(
context
.
Context
,
io
.
Reader
)
(
*
cid
.
Cid
,
error
)
Cat
(
context
.
Context
,
string
)
(
Reader
,
error
)
...
...
core/coreapi/unixfs.go
浏览文件 @
e260d2fd
...
...
@@ -4,7 +4,6 @@ import (
"context"
"io"
core
"github.com/ipfs/go-ipfs/core"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
...
...
@@ -12,14 +11,7 @@ import (
cid
"gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
)
type
UnixfsAPI
struct
{
node
*
core
.
IpfsNode
}
func
NewUnixfsAPI
(
n
*
core
.
IpfsNode
)
coreiface
.
UnixfsAPI
{
api
:=
&
UnixfsAPI
{
n
}
return
api
}
type
UnixfsAPI
CoreAPI
func
(
api
*
UnixfsAPI
)
Add
(
ctx
context
.
Context
,
r
io
.
Reader
)
(
*
cid
.
Cid
,
error
)
{
k
,
err
:=
coreunix
.
AddWithContext
(
ctx
,
api
.
node
,
r
)
...
...
core/coreapi/unixfs_test.go
浏览文件 @
e260d2fd
...
...
@@ -41,7 +41,7 @@ func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.UnixfsAPI, error) {
if
err
!=
nil
{
return
nil
,
nil
,
err
}
api
:=
coreapi
.
New
UnixfsAPI
(
node
)
api
:=
coreapi
.
New
CoreAPI
(
node
)
.
Unixfs
(
)
return
node
,
api
,
nil
}
...
...
core/corehttp/gateway.go
浏览文件 @
e260d2fd
...
...
@@ -28,7 +28,7 @@ func GatewayOption(writable bool, paths ...string) ServeOption {
Headers
:
cfg
.
Gateway
.
HTTPHeaders
,
Writable
:
writable
,
PathPrefixes
:
cfg
.
Gateway
.
PathPrefixes
,
},
coreapi
.
New
Unixfs
API
(
n
))
},
coreapi
.
New
Core
API
(
n
))
for
_
,
p
:=
range
paths
{
mux
.
Handle
(
p
+
"/"
,
gateway
)
...
...
core/corehttp/gateway_handler.go
浏览文件 @
e260d2fd
...
...
@@ -37,10 +37,10 @@ const (
type
gatewayHandler
struct
{
node
*
core
.
IpfsNode
config
GatewayConfig
api
coreiface
.
Unixfs
API
api
coreiface
.
Core
API
}
func
newGatewayHandler
(
n
*
core
.
IpfsNode
,
c
GatewayConfig
,
api
coreiface
.
Unixfs
API
)
*
gatewayHandler
{
func
newGatewayHandler
(
n
*
core
.
IpfsNode
,
c
GatewayConfig
,
api
coreiface
.
Core
API
)
*
gatewayHandler
{
i
:=
&
gatewayHandler
{
node
:
n
,
config
:
c
,
...
...
@@ -158,7 +158,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
ipnsHostname
=
true
}
dr
,
err
:=
i
.
api
.
Cat
(
ctx
,
urlPath
)
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
urlPath
)
dir
:=
false
switch
err
{
case
nil
:
...
...
@@ -218,7 +218,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
links
,
err
:=
i
.
api
.
Ls
(
ctx
,
urlPath
)
links
,
err
:=
i
.
api
.
Unixfs
()
.
Ls
(
ctx
,
urlPath
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -247,7 +247,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}
// return index page instead.
dr
,
err
:=
i
.
api
.
Cat
(
ctx
,
p
.
String
())
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
p
.
String
())
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -314,7 +314,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}
func
(
i
*
gatewayHandler
)
postHandler
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
k
,
err
:=
i
.
api
.
Add
(
ctx
,
r
.
Body
)
k
,
err
:=
i
.
api
.
Unixfs
()
.
Add
(
ctx
,
r
.
Body
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论