Add *Ctx methods for calling SOAP methods.

Fixes #42.
This commit is contained in:
John Beisley 2021-07-11 14:53:32 +01:00
parent 9eb592fa19
commit 5a0d4bd7ee
4 changed files with 6409 additions and 1374 deletions

View File

@ -17,6 +17,7 @@ package {{$name}}
// *********************************************************** // ***********************************************************
import ( import (
"context"
"net/url" "net/url"
"time" "time"
@ -115,8 +116,10 @@ func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceCl
// Return values:{{range $woutargs}}{{if .HasDoc}} // Return values:{{range $woutargs}}{{if .HasDoc}}
// //
// * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}} // * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}}
func (client *{{$srvIdent}}) {{.Name}}({{range $winargs -}} func (client *{{$srvIdent}}) {{.Name}}Ctx(
{{.AsParameter}}, {{end -}} ctx context.Context,
{{range $winargs }} {{.AsParameter}},
{{end -}}
) ({{range $woutargs -}} ) ({{range $woutargs -}}
{{.AsParameter}}, {{end}} err error) { {{.AsParameter}}, {{end}} err error) {
// Request structure. // Request structure.
@ -132,7 +135,7 @@ func (client *{{$srvIdent}}) {{.Name}}({{range $winargs -}}
response := {{if $woutargs}}&{{template "argstruct" $woutargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}} response := {{if $woutargs}}&{{template "argstruct" $woutargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}}
// Perform the SOAP call. // Perform the SOAP call.
if err = client.SOAPClient.PerformAction({{$srv.URNParts.Const}}, "{{.Name}}", request, response); err != nil { if err = client.SOAPClient.PerformActionCtx(ctx, {{$srv.URNParts.Const}}, "{{.Name}}", request, response); err != nil {
return return
} }
@ -144,6 +147,19 @@ func (client *{{$srvIdent}}) {{.Name}}({{range $winargs -}}
// END Unmarshal arguments from response. // END Unmarshal arguments from response.
return return
} }
// {{.Name}} is the legacy version of {{.Name}}Ctx, but uses
// context.Background() as the context.
func (client *{{$srvIdent}}) {{.Name}}({{range $winargs -}}
{{.AsParameter}}, {{end -}}
) ({{range $woutargs -}}
{{.AsParameter}}, {{end}} err error) {
return client.{{.Name}}Ctx(context.Background(),
{{range $winargs }}{{.Name}},
{{end}}
)
}
{{end}} {{end}}
{{end}} {{end}}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff