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
Show 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")
...
@@ -14,7 +14,7 @@ var log = u.Logger("command")
// Function is the type of function that Commands use.
// Function is the type of function that Commands use.
// It reads from the Request, and writes results to the Response.
// 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
// Marshaler is a function that takes in a Response, and returns an io.Reader
// (or an error on failure)
// (or an error on failure)
...
@@ -95,21 +95,12 @@ func (c *Command) Call(req Request) Response {
...
@@ -95,21 +95,12 @@ func (c *Command) Call(req Request) Response {
return
res
return
res
}
}
output
,
err
:=
cmd
.
Run
(
req
)
cmd
.
Run
(
req
,
res
)
if
err
!=
nil
{
if
res
.
Error
()
!=
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
)
}
return
res
return
res
}
}
output
:=
res
.
Output
()
isChan
:=
false
isChan
:=
false
actualType
:=
reflect
.
TypeOf
(
output
)
actualType
:=
reflect
.
TypeOf
(
output
)
if
actualType
!=
nil
{
if
actualType
!=
nil
{
...
@@ -140,7 +131,6 @@ func (c *Command) Call(req Request) Response {
...
@@ -140,7 +131,6 @@ func (c *Command) Call(req Request) Response {
}
}
}
}
res
.
SetOutput
(
output
)
return
res
return
res
}
}
...
...
command_test.go
View file @
970b570f
...
@@ -2,8 +2,8 @@ package commands
...
@@ -2,8 +2,8 @@ package commands
import
"testing"
import
"testing"
func
noop
(
req
Request
)
(
interface
{},
error
)
{
func
noop
(
req
Request
,
res
Response
)
{
return
nil
,
nil
return
}
}
func
TestOptionValidation
(
t
*
testing
.
T
)
{
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