goupnp/v2alpha/srv/srv.gotemplate

81 lines
2.5 KiB
Plaintext
Raw Normal View History

2022-06-06 17:00:39 +00:00
{{define "service"}}
2022-06-08 06:05:49 +00:00
{{- $Imps := .Imps -}}
{{- $Types := .Types -}}
// Package {{.Manifest.Package}} provides types for the {{quote .Manifest.ServiceType}} service.
{{- with .Manifest.DocumentURL}}
//
// Documented at {{.}}.
{{- end}}
package {{.Manifest.Package}}
2022-06-06 17:00:39 +00:00
import (
{{- range .Imps.ImportLines}}
{{.Alias}} {{quote .Path}}
2022-06-06 17:00:39 +00:00
{{- end}}
)
{{range .Types.StringVarDefs}}
{{- $Name := .Name}}
{{- with .AllowedValues}}
// Allowed values for state variable {{$Name}}.
const (
{{- range .}}
{{$Name}}_{{.}} = "{{.}}"
{{- end}}
)
{{- end}}
{{- end}}
const ServiceType = {{quote .Manifest.ServiceType}}
2022-06-06 17:00:39 +00:00
{{range .SCPD.SortedActions}}
{{- template "action" args "Action" . "Imps" $Imps "Types" $Types}}
2022-06-06 17:00:39 +00:00
{{end}}
{{- end}}
2022-06-06 17:00:39 +00:00
{{define "action"}}
2022-06-08 06:05:49 +00:00
{{- $Imps := .Imps}}
{{- $Types := .Types}}
{{- $soapActionType := index $Types.TypeByName "SOAPActionInterface"}}
// {{.Action.Name}} provides request and response for the action.
//
// ServiceType implements {{$soapActionType.AbsRef}}, self-describing the SOAP action.
type {{.Action.Name}} struct{
Request {{.Action.Name}}Request
Response {{.Action.Name}}Response
}
var _ {{$soapActionType.Ref}} = &{{.Action.Name}}{{"{}"}}
// ServiceType implements {{$soapActionType.AbsRef}}.
func (a *{{.Action.Name}}) ServiceType() string { return ServiceType }
// ActionName implements {{$soapActionType.AbsRef}}.
func (a *{{.Action.Name}}) ActionName() string { return {{quote .Action.Name}} }
// RefRequest implements {{$soapActionType.AbsRef}}.
func (a *{{.Action.Name}}) RefRequest() any { return &a.Request }
// RefResponse implements {{$soapActionType.AbsRef}}.
func (a *{{.Action.Name}}) RefResponse() any { return &a.Response }
// {{.Action.Name}}Request contains the "in" args for the {{quote .Action.Name}} action.
2022-06-08 06:05:49 +00:00
type {{.Action.Name}}Request struct
{{- template "args" args "Args" .Action.InArgs "Imps" $Imps "Types" $Types}}
2022-06-06 17:00:39 +00:00
// {{.Action.Name}}Response contains the "out" args for the {{quote .Action.Name}} action.
2022-06-08 06:05:49 +00:00
type {{.Action.Name}}Response struct
{{- template "args" args "Args" .Action.OutArgs "Imps" $Imps "Types" $Types}}
2022-06-06 17:00:39 +00:00
{{- end}}
{{define "args"}}
2022-06-08 06:05:49 +00:00
{{- $Imps := .Imps -}}
{{- $Types := .Types -}}
2022-06-08 06:05:49 +00:00
{ {{- with .Args}}
{{- range .}}
{{- $fieldType := index $Types.TypeByName .RelatedStateVariable.DataType}}
// {{.Name}} relates to state variable {{.RelatedStateVariable.Name}}
{{- with .RelatedStateVariable.AllowedValues}}
{{- ""}} ({{len .}} standard allowed values)
{{- end }}.
{{.Name}} {{$fieldType.Ref}}
{{- end}}
2022-06-08 06:05:49 +00:00
{{end -}} }
2022-06-06 17:00:39 +00:00
{{- end}}