Add streams to proc arguments, use requestStream

This makes functions look just like in actual libvirt API, except
virStreamPtr is replaced with io.Reader for outgoing streams and
io.Writer for incoming streams.
This commit is contained in:
Yuriy Taraday 2018-02-26 00:56:27 +04:00
parent 3613b30fe2
commit 02e0818aef
2 changed files with 411 additions and 400 deletions

View File

@ -23,6 +23,7 @@ package libvirt
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"github.com/davecgh/go-xdr/xdr2" "github.com/davecgh/go-xdr/xdr2"
"github.com/digitalocean/go-libvirt/internal/constants" "github.com/digitalocean/go-libvirt/internal/constants"
@ -126,9 +127,15 @@ func decodeTypedParams(dec *xdr.Decoder) ([]TypedParam, error) {
return params, nil return params, nil
} }
{{range .Procs}} {{range $proc := .Procs}}
// {{.Name}} is the go wrapper for {{.LVName}}. // {{.Name}} is the go wrapper for {{.LVName}}.
func (l *Libvirt) {{.Name}}({{range $ix, $arg := .Args}}{{if $ix}}, {{end}}{{.Name}} {{.Type}}{{end}}) ({{range .Ret}}r{{.Name}} {{.Type}}, {{end}}err error) { func (l *Libvirt) {{.Name}}(
{{- range $ix, $arg := .Args}}
{{- if (eq $ix $proc.WriteStreamIdx)}}{{if $ix}}, {{end}}outStream io.Reader{{end}}
{{- if (eq $ix $proc.ReadStreamIdx)}}{{if $ix}}, {{end}}inStream io.Writer{{end}}
{{- if $ix}}, {{end}}{{.Name}} {{.Type}}
{{- end -}}
) ({{range .Ret}}r{{.Name}} {{.Type}}, {{end}}err error) {
var buf []byte var buf []byte
{{if .ArgsStruct}} {{if .ArgsStruct}}
args := {{.ArgsStruct}} { args := {{.ArgsStruct}} {
@ -141,7 +148,10 @@ func (l *Libvirt) {{.Name}}({{range $ix, $arg := .Args}}{{if $ix}}, {{end}}{{.Na
} }
{{end}} {{end}}
{{if .RetStruct}} var r response{{end}} {{if .RetStruct}} var r response{{end}}
{{if .RetStruct}}r{{else}}_{{end}}, err = l.request({{.Num}}, constants.Program, buf) {{if .RetStruct}}r{{else}}_{{end}}, err = l.requestStream({{.Num}}, constants.Program, buf,
{{- if (ne .WriteStreamIdx -1)}} outStream,{{else}} nil,{{end}}
{{- if (ne .ReadStreamIdx -1)}} inStream{{else}} nil{{end -}}
)
if err != nil { if err != nil {
return return
} }

File diff suppressed because it is too large Load Diff