commands: Replaced 'Formatter' with 'Marshaller'
Matt Bell committed
Nov 3, 2014 at 23:02 UTC
0149f65c6c3d3b58d2a6c8b6db4da56a37951898
2 files changed
+5
-10
commands/command.go
+3
-4
@@ -15,10 +15,9 @@ var log = u.Logger("command")
15
// It reads from the Request, and writes results to the Response.
16
type Function func(Response, Request)
17
18
-// Formatter is a function that takes in a Response, and returns a human-readable string
18
+// Marshaller is a function that takes in a Response, and returns a marshalled []byte
19
// (or an error on failure)
20
-// MAYBE_TODO: maybe this should be a io.Reader instead of a string?
21
-type Formatter func(Response) (string, error)
20
+type Marshaller func(Response) ([]byte, error)
21
22
// TODO: check Argument definitions when creating a Command
23
// (might need to use a Command constructor)
@@ -33,7 +32,7 @@ type Command struct {
32
Options []Option
33
Arguments []Argument
34
Run Function
36
- Format Formatter
35
+ Format Marshaller
36
Type interface{}
37
Subcommands map[string]*Command
38
}
commands/response.go
+2
-6
@@ -40,10 +40,6 @@ const (
40
// TODO: support more encoding types
41
)
42
43
-// Marshaller is a function used by coding types.
44
-// TODO this should just be a `coding.Codec`
45
-type Marshaller func(res Response) ([]byte, error)
46
-
43
var marshallers = map[EncodingType]Marshaller{
44
JSON: func(res Response) ([]byte, error) {
45
if res.Error() != nil {
@@ -63,11 +59,11 @@ var marshallers = map[EncodingType]Marshaller{
59
return nil, ErrNoFormatter
60
}
61
66
- s, err := format(res)
62
+ bytes, err := format(res)
63
if err != nil {
64
return nil, err
65
}
70
- return []byte(s), nil
66
+ return bytes, nil
67
},
68
}
69