You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/cmd/protoc-gen-go-errors/template.go

36 lines
552 B

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()
}