Move fetching response from channel to request() method

Also parse error on bad status in request method.
This pattern was scattered all over the place.
This commit is contained in:
Yuriy Taraday
2018-01-29 00:33:02 +04:00
parent 338b59a53a
commit 47db3dbbbc
4 changed files with 802 additions and 3180 deletions

View File

@@ -140,17 +140,11 @@ func (l *Libvirt) {{.Name}}({{range $ix, $arg := .Args}}{{if $ix}}, {{end}}{{.Na
return
}
{{end}}
var resp <-chan response
resp, err = l.request({{.Num}}, constants.Program, &buf)
{{if .RetStruct}} var r response{{end}}
{{if .RetStruct}}r{{else}}_{{end}}, err = l.request({{.Num}}, constants.Program, &buf)
if err != nil {
return
}
r := <-resp
if r.Status != StatusOK {
err = decodeError(r.Payload)
return
}
{{if .RetStruct}}
// Return value unmarshaling
rdr := bytes.NewReader(r.Payload)