@cryptotaxi247 / kubo / commits / 77e5742ac

commands/http: client: Decode values into a new instance of the output type

Matt Bell committed Jan 6, 2015 at 11:34 UTC 77e5742ac753f0b88fefb066d31cdc653cba9b15
1 file changed +6 -5
commands/http/client.go
+6 -5
@@ -150,11 +150,11 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
150 outChan := make(chan interface{})
151 go func() {
152 dec := json.NewDecoder(httpRes.Body)
153 - outputType := reflect.ValueOf(req.Command().Type).Type()
154 - v := reflect.New(outputType).Interface()
153 + outputType := reflect.TypeOf(req.Command().Type)
154
155 for {
157 - err := dec.Decode(&v)
156 + v := reflect.New(outputType).Interface()
157 + err := dec.Decode(v)
158 if err != nil && err != io.EOF {
159 fmt.Println(err.Error())
160 return
@@ -199,8 +199,9 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
199 res.SetError(e, e.Code)
200
201 } else {
202 - v := req.Command().Type
203 - err = dec.Decode(&v)
202 + outputType := reflect.TypeOf(req.Command().Type)
203 + v := reflect.New(outputType).Interface()
204 + err = dec.Decode(v)
205 if err != nil && err != io.EOF {
206 return nil, err
207 }