mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
commands: Renamed Response#Value to Response#Output
This commit is contained in:

committed by
Juan Batiz-Benet

parent
75649f3d49
commit
69a56de040
@ -80,7 +80,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
|
||||
contentType = strings.Split(contentType, ";")[0]
|
||||
|
||||
if contentType == "application/octet-stream" {
|
||||
res.SetValue(httpRes.Body)
|
||||
res.SetOutput(httpRes.Body)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ func Send(req cmds.Request) (cmds.Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res.SetValue(v)
|
||||
res.SetOutput(v)
|
||||
}
|
||||
|
||||
if len(userEncoding) > 0 {
|
||||
|
@ -38,7 +38,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
res := i.Root.Call(req)
|
||||
|
||||
// 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
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
} else {
|
||||
|
@ -49,13 +49,13 @@ var marshallers = map[EncodingType]Marshaller{
|
||||
if res.Error() != nil {
|
||||
return json.Marshal(res.Error())
|
||||
}
|
||||
return json.Marshal(res.Value())
|
||||
return json.Marshal(res.Output())
|
||||
},
|
||||
XML: func(res Response) ([]byte, error) {
|
||||
if res.Error() != nil {
|
||||
return xml.Marshal(res.Error())
|
||||
}
|
||||
return xml.Marshal(res.Value())
|
||||
return xml.Marshal(res.Output())
|
||||
},
|
||||
Text: func(res Response) ([]byte, error) {
|
||||
format := res.Request().Command().Format
|
||||
@ -83,8 +83,8 @@ type Response interface {
|
||||
Error() *Error
|
||||
|
||||
// Sets/Returns the response value
|
||||
SetValue(interface{})
|
||||
Value() interface{}
|
||||
SetOutput(interface{})
|
||||
Output() interface{}
|
||||
|
||||
// Marshal marshals out the response into a buffer. It uses the EncodingType
|
||||
// on the Request to chose a Marshaller (Codec).
|
||||
@ -102,11 +102,11 @@ func (r *response) Request() Request {
|
||||
return r.req
|
||||
}
|
||||
|
||||
func (r *response) Value() interface{} {
|
||||
func (r *response) Output() interface{} {
|
||||
return r.value
|
||||
}
|
||||
|
||||
func (r *response) SetValue(v interface{}) {
|
||||
func (r *response) SetOutput(v interface{}) {
|
||||
r.value = v
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ func TestMarshalling(t *testing.T) {
|
||||
req := NewEmptyRequest()
|
||||
|
||||
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
|
||||
cmd := Command{}
|
||||
|
Reference in New Issue
Block a user