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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user