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