Commit 970b570f authored by Matt Bell's avatar Matt Bell

commands: Refactored Command#Run function signature to (req Request, res Response)

parent d3f17bd4
......@@ -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
}
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment