提交 69a56de0 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: Renamed Response#Value to Response#Output

上级 75649f3d
...@@ -80,7 +80,7 @@ func Send(req cmds.Request) (cmds.Response, error) { ...@@ -80,7 +80,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
contentType = strings.Split(contentType, ";")[0] contentType = strings.Split(contentType, ";")[0]
if contentType == "application/octet-stream" { if contentType == "application/octet-stream" {
res.SetValue(httpRes.Body) res.SetOutput(httpRes.Body)
return res, nil return res, nil
} }
...@@ -120,7 +120,7 @@ func Send(req cmds.Request) (cmds.Response, error) { ...@@ -120,7 +120,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
return nil, err return nil, err
} }
res.SetValue(v) res.SetOutput(v)
} }
if len(userEncoding) > 0 { if len(userEncoding) > 0 {
......
...@@ -38,7 +38,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -38,7 +38,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
res := i.Root.Call(req) res := i.Root.Call(req)
// set the Content-Type based on res output // set the Content-Type based on res output
if _, ok := res.Value().(io.Reader); ok { if _, ok := res.Output().(io.Reader); ok {
// TODO: set based on actual Content-Type of file // TODO: set based on actual Content-Type of file
w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Content-Type", "application/octet-stream")
} else { } else {
......
...@@ -49,13 +49,13 @@ var marshallers = map[EncodingType]Marshaller{ ...@@ -49,13 +49,13 @@ var marshallers = map[EncodingType]Marshaller{
if res.Error() != nil { if res.Error() != nil {
return json.Marshal(res.Error()) return json.Marshal(res.Error())
} }
return json.Marshal(res.Value()) return json.Marshal(res.Output())
}, },
XML: func(res Response) ([]byte, error) { XML: func(res Response) ([]byte, error) {
if res.Error() != nil { if res.Error() != nil {
return xml.Marshal(res.Error()) return xml.Marshal(res.Error())
} }
return xml.Marshal(res.Value()) return xml.Marshal(res.Output())
}, },
Text: func(res Response) ([]byte, error) { Text: func(res Response) ([]byte, error) {
format := res.Request().Command().Format format := res.Request().Command().Format
...@@ -83,8 +83,8 @@ type Response interface { ...@@ -83,8 +83,8 @@ type Response interface {
Error() *Error Error() *Error
// Sets/Returns the response value // Sets/Returns the response value
SetValue(interface{}) SetOutput(interface{})
Value() interface{} Output() interface{}
// Marshal marshals out the response into a buffer. It uses the EncodingType // Marshal marshals out the response into a buffer. It uses the EncodingType
// on the Request to chose a Marshaller (Codec). // on the Request to chose a Marshaller (Codec).
...@@ -102,11 +102,11 @@ func (r *response) Request() Request { ...@@ -102,11 +102,11 @@ func (r *response) Request() Request {
return r.req return r.req
} }
func (r *response) Value() interface{} { func (r *response) Output() interface{} {
return r.value return r.value
} }
func (r *response) SetValue(v interface{}) { func (r *response) SetOutput(v interface{}) {
r.value = v r.value = v
} }
......
...@@ -14,7 +14,7 @@ func TestMarshalling(t *testing.T) { ...@@ -14,7 +14,7 @@ func TestMarshalling(t *testing.T) {
req := NewEmptyRequest() req := NewEmptyRequest()
res := NewResponse(req) res := NewResponse(req)
res.SetValue(TestOutput{"beep", "boop", 1337}) res.SetOutput(TestOutput{"beep", "boop", 1337})
// get command global options so we can set the encoding option // get command global options so we can set the encoding option
cmd := Command{} cmd := Command{}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论