Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
827f1dd0
提交
827f1dd0
authored
11月 02, 2014
作者:
Matt Bell
提交者:
Juan Batiz-Benet
11月 04, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands: Changed Request arguments to a []interface{}
上级
30e96875
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
36 行增加
和
20 行删除
+36
-20
argument.go
commands/argument.go
+14
-0
parse.go
commands/cli/parse.go
+2
-2
command.go
commands/command.go
+1
-0
client.go
commands/http/client.go
+5
-2
parse.go
commands/http/parse.go
+9
-11
request.go
commands/request.go
+5
-5
没有找到文件。
commands/argument.go
0 → 100644
浏览文件 @
827f1dd0
package
commands
type
ArgumentType
int
const
(
ArgString
ArgumentType
=
iota
ArgPath
)
type
Argument
struct
{
Name
string
Type
ArgumentType
Required
,
Variadic
bool
}
commands/cli/parse.go
浏览文件 @
827f1dd0
...
@@ -65,9 +65,9 @@ func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Co
...
@@ -65,9 +65,9 @@ func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Co
// parseOptions parses the raw string values of the given options
// parseOptions parses the raw string values of the given options
// returns the parsed options as strings, along with the CLI args
// returns the parsed options as strings, along with the CLI args
func
parseOptions
(
input
[]
string
)
(
map
[
string
]
interface
{},
[]
string
,
error
)
{
func
parseOptions
(
input
[]
string
)
(
map
[
string
]
interface
{},
[]
interface
{}
,
error
)
{
opts
:=
make
(
map
[
string
]
interface
{})
opts
:=
make
(
map
[
string
]
interface
{})
args
:=
[]
string
{}
args
:=
[]
interface
{}
{}
for
i
:=
0
;
i
<
len
(
input
);
i
++
{
for
i
:=
0
;
i
<
len
(
input
);
i
++
{
blob
:=
input
[
i
]
blob
:=
input
[
i
]
...
...
commands/command.go
浏览文件 @
827f1dd0
...
@@ -24,6 +24,7 @@ type Formatter func(Response) (string, error)
...
@@ -24,6 +24,7 @@ type Formatter func(Response) (string, error)
type
Command
struct
{
type
Command
struct
{
Help
string
Help
string
Options
[]
Option
Options
[]
Option
Arguments
[]
Argument
Run
Function
Run
Function
Format
Formatter
Format
Formatter
Type
interface
{}
Type
interface
{}
...
...
commands/http/client.go
浏览文件 @
827f1dd0
...
@@ -44,8 +44,11 @@ func Send(req cmds.Request) (cmds.Response, error) {
...
@@ -44,8 +44,11 @@ func Send(req cmds.Request) (cmds.Response, error) {
for
k
,
v
:=
range
req
.
Options
()
{
for
k
,
v
:=
range
req
.
Options
()
{
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
}
}
for
_
,
v
:=
range
req
.
Arguments
()
{
for
_
,
arg
:=
range
req
.
Arguments
()
{
query
+=
"&arg="
+
v
s
,
ok
:=
arg
.
(
string
)
if
ok
{
query
+=
"&arg="
+
s
}
}
}
httpRes
,
err
:=
http
.
Post
(
url
+
query
,
"application/octet-stream"
,
req
.
Stream
())
httpRes
,
err
:=
http
.
Post
(
url
+
query
,
"application/octet-stream"
,
req
.
Stream
())
...
...
commands/http/parse.go
浏览文件 @
827f1dd0
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
// Parse parses the data in a http.Request and returns a command Request object
// Parse parses the data in a http.Request and returns a command Request object
func
Parse
(
r
*
http
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
error
)
{
func
Parse
(
r
*
http
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
error
)
{
path
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)[
3
:
]
path
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)[
3
:
]
args
:=
make
([]
string
,
0
)
args
:=
make
([]
interface
{}
,
0
)
cmd
,
err
:=
root
.
Get
(
path
[
:
len
(
path
)
-
1
])
cmd
,
err
:=
root
.
Get
(
path
[
:
len
(
path
)
-
1
])
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -34,28 +34,26 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -34,28 +34,26 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
opts
,
args2
:=
parseOptions
(
r
)
opts
,
args2
:=
parseOptions
(
r
)
args
=
append
(
args
,
args2
...
)
args
=
append
(
args
,
args2
...
)
// TODO: make a way to send opts/args in request body
return
cmds
.
NewRequest
(
path
,
opts
,
args
,
nil
,
cmd
),
nil
// (e.g. if form-data or form-urlencoded, then treat the same as querystring)
// for now, to be simple, we just use the whole request body as the input stream
// (r.Body will be nil if there is no request body, like in GET requests)
in
:=
r
.
Body
return
cmds
.
NewRequest
(
path
,
opts
,
args
,
in
,
cmd
),
nil
}
}
func
parseOptions
(
r
*
http
.
Request
)
(
map
[
string
]
interface
{},
[]
string
)
{
func
parseOptions
(
r
*
http
.
Request
)
(
map
[
string
]
interface
{},
[]
interface
{}
)
{
opts
:=
make
(
map
[
string
]
interface
{})
opts
:=
make
(
map
[
string
]
interface
{})
var
args
[]
string
args
:=
make
([]
interface
{},
0
)
query
:=
r
.
URL
.
Query
()
query
:=
r
.
URL
.
Query
()
for
k
,
v
:=
range
query
{
for
k
,
v
:=
range
query
{
if
k
==
"arg"
{
if
k
==
"arg"
{
args
=
v
for
_
,
s
:=
range
v
{
args
=
append
(
args
,
interface
{}(
s
))
}
}
else
{
}
else
{
opts
[
k
]
=
v
[
0
]
opts
[
k
]
=
v
[
0
]
}
}
}
}
// TODO: create multipart streams for file args
// default to setting encoding to JSON
// default to setting encoding to JSON
_
,
short
:=
opts
[
cmds
.
EncShort
]
_
,
short
:=
opts
[
cmds
.
EncShort
]
_
,
long
:=
opts
[
cmds
.
EncLong
]
_
,
long
:=
opts
[
cmds
.
EncLong
]
...
...
commands/request.go
浏览文件 @
827f1dd0
...
@@ -24,7 +24,7 @@ type Request interface {
...
@@ -24,7 +24,7 @@ type Request interface {
Option
(
name
string
)
(
interface
{},
bool
)
Option
(
name
string
)
(
interface
{},
bool
)
Options
()
map
[
string
]
interface
{}
Options
()
map
[
string
]
interface
{}
SetOption
(
name
string
,
val
interface
{})
SetOption
(
name
string
,
val
interface
{})
Arguments
()
[]
string
Arguments
()
[]
interface
{}
// TODO: make argument value type instead of using interface{}
Stream
()
io
.
Reader
Stream
()
io
.
Reader
SetStream
(
io
.
Reader
)
SetStream
(
io
.
Reader
)
Context
()
*
Context
Context
()
*
Context
...
@@ -37,7 +37,7 @@ type Request interface {
...
@@ -37,7 +37,7 @@ type Request interface {
type
request
struct
{
type
request
struct
{
path
[]
string
path
[]
string
options
optMap
options
optMap
arguments
[]
string
arguments
[]
interface
{}
in
io
.
Reader
in
io
.
Reader
cmd
*
Command
cmd
*
Command
ctx
Context
ctx
Context
...
@@ -69,7 +69,7 @@ func (r *request) SetOption(name string, val interface{}) {
...
@@ -69,7 +69,7 @@ func (r *request) SetOption(name string, val interface{}) {
}
}
// Arguments returns the arguments slice
// Arguments returns the arguments slice
func
(
r
*
request
)
Arguments
()
[]
string
{
func
(
r
*
request
)
Arguments
()
[]
interface
{}
{
return
r
.
arguments
return
r
.
arguments
}
}
...
@@ -165,7 +165,7 @@ func NewEmptyRequest() Request {
...
@@ -165,7 +165,7 @@ func NewEmptyRequest() Request {
}
}
// NewRequest returns a request initialized with given arguments
// NewRequest returns a request initialized with given arguments
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
string
,
in
io
.
Reader
,
cmd
*
Command
)
Request
{
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{}
,
in
io
.
Reader
,
cmd
*
Command
)
Request
{
if
path
==
nil
{
if
path
==
nil
{
path
=
make
([]
string
,
0
)
path
=
make
([]
string
,
0
)
}
}
...
@@ -173,7 +173,7 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader, cmd *Co
...
@@ -173,7 +173,7 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader, cmd *Co
opts
=
make
(
map
[
string
]
interface
{})
opts
=
make
(
map
[
string
]
interface
{})
}
}
if
args
==
nil
{
if
args
==
nil
{
args
=
make
([]
string
,
0
)
args
=
make
([]
interface
{}
,
0
)
}
}
return
&
request
{
path
,
opts
,
args
,
in
,
cmd
,
Context
{}}
return
&
request
{
path
,
opts
,
args
,
in
,
cmd
,
Context
{}}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论