From 0149f65c6c3d3b58d2a6c8b6db4da56a37951898 Mon Sep 17 00:00:00 2001 From: Matt Bell <mappum@gmail.com> Date: Mon, 3 Nov 2014 23:02:50 -0800 Subject: [PATCH] commands: Replaced 'Formatter' with 'Marshaller' --- commands/command.go | 7 +++---- commands/response.go | 8 ++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/commands/command.go b/commands/command.go index 2ecb6ee29..17487b7e1 100644 --- a/commands/command.go +++ b/commands/command.go @@ -15,10 +15,9 @@ var log = u.Logger("command") // It reads from the Request, and writes results to the Response. type Function func(Response, Request) -// Formatter is a function that takes in a Response, and returns a human-readable string +// Marshaller is a function that takes in a Response, and returns a marshalled []byte // (or an error on failure) -// MAYBE_TODO: maybe this should be a io.Reader instead of a string? -type Formatter func(Response) (string, error) +type Marshaller func(Response) ([]byte, error) // TODO: check Argument definitions when creating a Command // (might need to use a Command constructor) @@ -33,7 +32,7 @@ type Command struct { Options []Option Arguments []Argument Run Function - Format Formatter + Format Marshaller Type interface{} Subcommands map[string]*Command } diff --git a/commands/response.go b/commands/response.go index f703299e8..8cc724f3d 100644 --- a/commands/response.go +++ b/commands/response.go @@ -40,10 +40,6 @@ const ( // TODO: support more encoding types ) -// Marshaller is a function used by coding types. -// TODO this should just be a `coding.Codec` -type Marshaller func(res Response) ([]byte, error) - var marshallers = map[EncodingType]Marshaller{ JSON: func(res Response) ([]byte, error) { if res.Error() != nil { @@ -63,11 +59,11 @@ var marshallers = map[EncodingType]Marshaller{ return nil, ErrNoFormatter } - s, err := format(res) + bytes, err := format(res) if err != nil { return nil, err } - return []byte(s), nil + return bytes, nil }, } -- GitLab