1 Star 0 Fork 0

东海苍月 / go-protobuf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
template.go 832 Bytes
一键复制 编辑 原始数据 按行查看 历史
东海苍月 提交于 2022-01-19 14:44 . feat: update error struct #0000
package main
import (
"bytes"
"text/template"
)
var errorsTemplate = `
{{ range .Errors }}
func Is{{.CamelValue}}(err error) bool {
if err == nil {
return false
}
e := errors.FromError(err)
return e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == "{{.Code}}"
}
func {{.CamelValue}}() *errors.Error {
return errors.New("{{.Code}}", {{.Name}}_{{.Value}}.String(), "{{.Message}}")
}
{{- end }}
`
type errorInfo struct {
Name string
Value string
Code string
Message string
CamelValue string
}
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
1
https://gitee.com/dhcy/go-protobuf.git
git@gitee.com:dhcy/go-protobuf.git
dhcy
go-protobuf
go-protobuf
df21623b900f

搜索帮助