Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
49792b23
提交
49792b23
authored
11月 11, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored cast errors to use a util
上级
f6c1cefe
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
39 行增加
和
30 行删除
+39
-30
client.go
commands/http/client.go
+4
-6
request.go
commands/request.go
+2
-2
add.go
core/commands2/add.go
+3
-2
block.go
core/commands2/block.go
+2
-3
bootstrap.go
core/commands2/bootstrap.go
+2
-2
config.go
core/commands2/config.go
+3
-2
slice_util.go
core/commands2/internal/slice_util.go
+4
-5
object.go
core/commands2/object.go
+7
-6
resolve.go
core/commands2/resolve.go
+2
-1
gen.go
util/testutil/gen.go
+1
-1
util.go
util/util.go
+9
-0
没有找到文件。
commands/http/client.go
浏览文件 @
49792b23
...
...
@@ -3,7 +3,6 @@ package http
import
(
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
...
...
@@ -11,10 +10,9 @@ import (
"strings"
cmds
"github.com/jbenet/go-ipfs/commands"
u
"github.com/jbenet/go-ipfs/util"
)
var
castError
=
errors
.
New
(
"cast error"
)
const
(
ApiUrlFormat
=
"http://%s%s/%s?%s"
ApiPath
=
"/api/v0"
// TODO: make configurable
...
...
@@ -70,7 +68,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
for
k
,
v
:=
range
req
.
Options
()
{
str
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
""
,
nil
,
castError
return
""
,
nil
,
u
.
ErrCast
()
}
query
.
Set
(
k
,
str
)
}
...
...
@@ -87,7 +85,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
if
argDef
.
Type
==
cmds
.
ArgString
{
str
,
ok
:=
arg
.
(
string
)
if
!
ok
{
return
""
,
nil
,
castError
return
""
,
nil
,
u
.
ErrCast
()
}
query
.
Add
(
"arg"
,
str
)
...
...
@@ -99,7 +97,7 @@ func getQuery(req cmds.Request) (string, io.Reader, error) {
var
ok
bool
inputStream
,
ok
=
arg
.
(
io
.
Reader
)
if
!
ok
{
return
""
,
nil
,
castError
return
""
,
nil
,
u
.
ErrCast
()
}
}
}
...
...
commands/request.go
浏览文件 @
49792b23
package
commands
import
(
"errors"
"fmt"
"io"
"reflect"
...
...
@@ -9,6 +8,7 @@ import (
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core"
u
"github.com/jbenet/go-ipfs/util"
)
type
optMap
map
[
string
]
interface
{}
...
...
@@ -176,7 +176,7 @@ func (r *request) ConvertOptions() error {
convert
:=
converters
[
opt
.
Type
]
str
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
errors
.
New
(
"cast error"
)
return
u
.
ErrCast
(
)
}
val
,
err
:=
convert
(
str
)
if
err
!=
nil
{
...
...
core/commands2/add.go
浏览文件 @
49792b23
...
...
@@ -17,6 +17,7 @@ import (
dag
"github.com/jbenet/go-ipfs/merkledag"
pinning
"github.com/jbenet/go-ipfs/pin"
ft
"github.com/jbenet/go-ipfs/unixfs"
u
"github.com/jbenet/go-ipfs/util"
)
// Error indicating the max depth has been exceded.
...
...
@@ -41,7 +42,7 @@ MerkleDAG. A smarter partial add with a staging area (like git)
remains to be implemented.
`
,
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
var
added
AddOutput
added
:=
&
AddOutput
{}
n
:=
req
.
Context
()
.
Node
recursive
,
err
:=
req
.
Option
(
"r"
)
.
Bool
()
...
...
@@ -167,7 +168,7 @@ remains to be implemented.
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
val
,
ok
:=
res
.
Output
()
.
(
*
AddOutput
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
var
buf
bytes
.
Buffer
...
...
core/commands2/block.go
浏览文件 @
49792b23
...
...
@@ -2,7 +2,6 @@ package commands
import
(
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
...
...
@@ -45,7 +44,7 @@ It outputs to stdout, and <key> is a base58 encoded multihash.`,
key
,
ok
:=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
if
!
u
.
IsValidHash
(
key
)
{
...
...
@@ -81,7 +80,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.`,
in
,
ok
:=
req
.
Arguments
()[
0
]
.
(
io
.
Reader
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
data
,
err
:=
ioutil
.
ReadAll
(
in
)
...
...
core/commands2/bootstrap.go
浏览文件 @
49792b23
package
commands
import
(
"errors"
"fmt"
"strings"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
u
"github.com/jbenet/go-ipfs/util"
cmds
"github.com/jbenet/go-ipfs/commands"
config
"github.com/jbenet/go-ipfs/config"
)
...
...
@@ -152,7 +152,7 @@ func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error)
for
_
,
v
:=
range
input
{
addr
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
addrS
,
peeridS
:=
split
(
addr
)
...
...
core/commands2/config.go
浏览文件 @
49792b23
...
...
@@ -12,6 +12,7 @@ import (
cmds
"github.com/jbenet/go-ipfs/commands"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
)
type
ConfigField
struct
{
...
...
@@ -45,7 +46,7 @@ var configCmd = &cmds.Command{
key
,
ok
:=
args
[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
filename
,
err
:=
config
.
Filename
(
req
.
Context
()
.
ConfigRoot
)
...
...
@@ -58,7 +59,7 @@ var configCmd = &cmds.Command{
var
ok
bool
value
,
ok
=
args
[
1
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
return
setConfig
(
filename
,
key
,
value
)
...
...
core/commands2/internal/slice_util.go
浏览文件 @
49792b23
package
internal
import
(
"errors"
"io"
)
var
CastErr
=
errors
.
New
(
"cast error"
)
u
"github.com/jbenet/go-ipfs/util"
)
func
CastToReaders
(
slice
[]
interface
{})
([]
io
.
Reader
,
error
)
{
readers
:=
make
([]
io
.
Reader
,
0
)
for
_
,
arg
:=
range
slice
{
reader
,
ok
:=
arg
.
(
io
.
Reader
)
if
!
ok
{
return
nil
,
CastErr
return
nil
,
u
.
ErrCast
()
}
readers
=
append
(
readers
,
reader
)
}
...
...
@@ -24,7 +23,7 @@ func CastToStrings(slice []interface{}) ([]string, error) {
for
_
,
maybe
:=
range
slice
{
str
,
ok
:=
maybe
.
(
string
)
if
!
ok
{
return
nil
,
CastErr
return
nil
,
u
.
ErrCast
()
}
strs
=
append
(
strs
,
str
)
}
...
...
core/commands2/object.go
浏览文件 @
49792b23
...
...
@@ -8,8 +8,9 @@ import (
"io/ioutil"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
core
"github.com/jbenet/go-ipfs/core"
dag
"github.com/jbenet/go-ipfs/merkledag"
u
"github.com/jbenet/go-ipfs/util"
)
// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 512k
...
...
@@ -51,7 +52,7 @@ output is the raw data of the object.
key
,
ok
:=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
return
objectData
(
n
,
key
)
...
...
@@ -71,7 +72,7 @@ It outputs to stdout, and <key> is a base58 encoded multihash.`,
key
,
ok
:=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
return
objectLinks
(
n
,
key
)
...
...
@@ -99,7 +100,7 @@ This command outputs data in the following encodings:
key
,
ok
:=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
object
,
err
:=
objectGet
(
n
,
key
)
...
...
@@ -151,12 +152,12 @@ Data should be in the format specified by <encoding>.
input
,
ok
:=
req
.
Arguments
()[
0
]
.
(
io
.
Reader
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
encoding
,
ok
:=
req
.
Arguments
()[
1
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
output
,
err
:=
objectPut
(
n
,
input
,
encoding
)
...
...
core/commands2/resolve.go
浏览文件 @
49792b23
...
...
@@ -4,6 +4,7 @@ import (
"errors"
cmds
"github.com/jbenet/go-ipfs/commands"
u
"github.com/jbenet/go-ipfs/util"
)
var
resolveCmd
=
&
cmds
.
Command
{
...
...
@@ -49,7 +50,7 @@ Resolve te value of another name:
var
ok
bool
name
,
ok
=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"cast error"
)
return
nil
,
u
.
ErrCast
(
)
}
}
...
...
util/testutil/gen.go
浏览文件 @
49792b23
package
testutil
import
(
"testing"
crand
"crypto/rand"
"testing"
"github.com/jbenet/go-ipfs/peer"
...
...
util/util.go
浏览文件 @
49792b23
...
...
@@ -8,6 +8,7 @@ import (
"math/rand"
"os"
"path/filepath"
"runtime/debug"
"strings"
"time"
...
...
@@ -40,6 +41,14 @@ func TildeExpansion(filename string) (string, error) {
return
homedir
.
Expand
(
filename
)
}
// ErrCast is returned when a cast fails AND the program should not panic.
func
ErrCast
()
error
{
debug
.
PrintStack
()
return
errCast
}
var
errCast
=
errors
.
New
(
"cast error"
)
// ExpandPathnames takes a set of paths and turns them into absolute paths
func
ExpandPathnames
(
paths
[]
string
)
([]
string
,
error
)
{
var
out
[]
string
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论