isle/go/daemon/jsonrpc2/client_gen.tpl

43 lines
1012 B
Smarty
Raw Normal View History

2024-09-04 19:24:45 +00:00
import (
"isle/daemon/jsonrpc2"
)
{{ $t := printf "%sClient" (down .Interface.Name) }}
type {{$t}} struct {
client jsonrpc2.Client
}
// {{.Interface.Name}}FromClient wraps a Client so that it implements the
// {{.Interface.Name}} interface.
func {{.Interface.Name}}FromClient(client jsonrpc2.Client) {{.Interface.Name}} {
return &{{$t}}{client}
}
{{range $method := .Interface.Methods}}
func (c *{{$t}}) {{$method.Declaration}} {
{{- $ctx := (index $method.Params 0).Name}}
{{- $rcv := ""}}
{{- $err := ""}}
{{- if (eq (len $method.Results) 1)}}
{{- $rcv = "nil" }}
{{- $err = (index $method.Results 0).Name}}
{{- else}}
{{- $rcv = printf "&%s" (index $method.Results 0).Name}}
{{- $err = (index $method.Results 1).Name}}
{{- end}}
{{- $err}} = c.client.Call(
{{$ctx}},
{{$rcv}},
"{{$method.Name}}",
{{- range $param := (slice $method.Params 1)}}
{{$param.Name}},
{{- end}}
)
2024-09-04 19:24:45 +00:00
return
}
{{end}}