提交 77e5742a 作者: Matt Bell

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

上级 ecc2248a
......@@ -150,11 +150,11 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
outChan := make(chan interface{})
go func() {
dec := json.NewDecoder(httpRes.Body)
outputType := reflect.ValueOf(req.Command().Type).Type()
v := reflect.New(outputType).Interface()
outputType := reflect.TypeOf(req.Command().Type)
for {
err := dec.Decode(&v)
v := reflect.New(outputType).Interface()
err := dec.Decode(v)
if err != nil && err != io.EOF {
fmt.Println(err.Error())
return
......@@ -199,8 +199,9 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
res.SetError(e, e.Code)
} else {
v := req.Command().Type
err = dec.Decode(&v)
outputType := reflect.TypeOf(req.Command().Type)
v := reflect.New(outputType).Interface()
err = dec.Decode(v)
if err != nil && err != io.EOF {
return nil, err
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论