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
970b570f
Commit
970b570f
authored
Jan 20, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Refactored Command#Run function signature to (req Request, res Response)
parent
d3f17bd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
16 deletions
+6
-16
command.go
command.go
+4
-14
command_test.go
command_test.go
+2
-2
No files found.
command.go
View file @
970b570f
...
...
@@ -14,7 +14,7 @@ var log = u.Logger("command")
// Function is the type of function that Commands use.
// It reads from the Request, and writes results to the Response.
type
Function
func
(
Request
)
(
interface
{},
error
)
type
Function
func
(
Request
,
Response
)
// Marshaler is a function that takes in a Response, and returns an io.Reader
// (or an error on failure)
...
...
@@ -95,21 +95,12 @@ func (c *Command) Call(req Request) Response {
return
res
}
output
,
err
:=
cmd
.
Run
(
req
)
if
err
!=
nil
{
// if returned error is a commands.Error, use its error code
// otherwise, just default the code to ErrNormal
switch
e
:=
err
.
(
type
)
{
case
*
Error
:
res
.
SetError
(
e
,
e
.
Code
)
case
Error
:
res
.
SetError
(
e
,
e
.
Code
)
default
:
res
.
SetError
(
err
,
ErrNormal
)
}
cmd
.
Run
(
req
,
res
)
if
res
.
Error
()
!=
nil
{
return
res
}
output
:=
res
.
Output
()
isChan
:=
false
actualType
:=
reflect
.
TypeOf
(
output
)
if
actualType
!=
nil
{
...
...
@@ -140,7 +131,6 @@ func (c *Command) Call(req Request) Response {
}
}
res
.
SetOutput
(
output
)
return
res
}
...
...
command_test.go
View file @
970b570f
...
...
@@ -2,8 +2,8 @@ package commands
import
"testing"
func
noop
(
req
Request
)
(
interface
{},
error
)
{
return
nil
,
nil
func
noop
(
req
Request
,
res
Response
)
{
return
}
func
TestOptionValidation
(
t
*
testing
.
T
)
{
...
...
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