forked from Memoria-X/protoc-gen-go-errors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
50 lines (43 loc) · 857 Bytes
/
template.go
File metadata and controls
50 lines (43 loc) · 857 Bytes
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
package main
import (
"bytes"
_ "embed"
"text/template"
)
//go:embed errorsTemplate.tpl
var errorsTemplate string
type errorInfo struct {
Name string
Value string
HTTPCode int
CamelValue string
Comment string
HasComment bool
}
type errorWrapper struct {
Errors []*errorInfo
}
func (e *errorWrapper) execute() string {
buf := new(bytes.Buffer)
tmpl, err := template.New("errors").Parse(errorsTemplate)
if err != nil {
panic(err)
}
if err := tmpl.Execute(buf, e); err != nil {
panic(err)
}
return buf.String()
}
//go:embed commonTemplate.tpl
var commonTemplate string
func executeCommon() string {
buf := new(bytes.Buffer)
commonTmpl, err := template.New("common").Parse(commonTemplate)
if err != nil {
panic(err)
}
if err := commonTmpl.Execute(buf, nil); err != nil {
panic(err)
}
return buf.String()
}