-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
60 lines (50 loc) · 1.32 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package template
import (
"io"
"text/template"
"unicode"
)
const tpl = `// Code generated by protoc-gen-twirpex {{ .GeneratorVersion }}, DO NOT EDIT.
// source: {{ .Proto.FileName }}
package {{ .GoPackage }}
import (
"github.com/albenik/twirpex"
)
func New{{ .Proto.ServiceName }}ServerEx(svc {{ .Proto.ServiceName }}, opts ...interface{}) twirpex.TwirpServer {
return New{{ .Proto.ServiceName }}Server(svc, opts...).(*{{ .Proto.ServiceName | lcfirst }}Server)
}
func (*{{ .Proto.ServiceName | lcfirst }}Server) TwirpServiceMeta() *twirpex.ServiceMeta {
return &twirpex.ServiceMeta {
PackageName: "{{ .Proto.PackageName }}",
ServiceName: "{{ .Proto.ServiceName }}",
ServiceFullName: "{{ .Proto.ServiceFullName }}",
MethodsNames: []string {
{{- range .Proto.MethodsNames }}
"{{ . }}",
{{- end }}
},
}
}
`
var t = template.Must(template.New("src").Funcs(template.FuncMap{
"lcfirst": func(s string) string {
r := []rune(s)
r[0] = unicode.ToLower(r[0])
return string(r)
},
}).Parse(tpl))
type Data struct {
GeneratorVersion string
GoPackage string
Proto Proto
}
type Proto struct {
FileName string
PackageName string
ServiceName string
ServiceFullName string
MethodsNames []string
}
func Execute(w io.Writer, data *Data) error {
return t.Execute(w, data)
}