Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
af93cfe5
Commit
af93cfe5
authored
Nov 11, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored cast errors to use a util
parent
d574d03a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
8 deletions
+6
-8
http/client.go
http/client.go
+4
-6
request.go
request.go
+2
-2
No files found.
http/client.go
View file @
af93cfe5
...
...
@@ -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
()
}
}
}
...
...
request.go
View file @
af93cfe5
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment