-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtemplate.h.go
49 lines (39 loc) · 1.27 KB
/
template.h.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
package main
import (
_ "embed"
"text/template"
"github.com/yeqown/protoc-gen-fieldmask/internal/templates"
"github.com/yeqown/protoc-gen-fieldmask/internal/templates/shared"
pgsgo "github.com/lyft/protoc-gen-star/lang/go"
)
func tplRegistryFactory(ctx pgsgo.Context) *templates.Registry {
registry := templates.New()
registry.Register("go", makeTemplatesForGo(ctx)) // lang=go
return registry
}
var (
//go:embed internal/templates/go/file.tpl
_tplFileGO []byte
//go:embed internal/templates/go/message.tpl
_tplMessageGO []byte
//go:embed internal/templates/go/fm.tpl
_tplFieldMaskGO []byte
//go:embed internal/templates/go/fm.in.tpl
_tplFieldMaskInGO []byte
//go:embed internal/templates/go/fm.out.tpl
_tplFieldMaskOutGO []byte
)
func makeTemplatesForGo(ctx pgsgo.Context) *templates.Lang {
tpl := template.New("go")
shared.RegisterFunctions(tpl, ctx)
template.Must(tpl.Parse(string(_tplFileGO)))
template.Must(tpl.New("message").Parse(string(_tplMessageGO)))
template.Must(tpl.New("fm").Parse(string(_tplFieldMaskGO)))
template.Must(tpl.New("fm.in").Parse(string(_tplFieldMaskInGO)))
template.Must(tpl.New("fm.out").Parse(string(_tplFieldMaskOutGO)))
return &templates.Lang{
Name: "go",
Ext: ".fm.go",
Templates: []*template.Template{tpl},
}
}