use goctl template to generate all kinds of templates

This commit is contained in:
kevin
2020-10-19 23:13:18 +08:00
parent 85a815bea0
commit dfe6e88529
35 changed files with 152 additions and 104 deletions

View File

@@ -12,7 +12,6 @@ import (
"github.com/tal-tech/go-zero/core/lang"
sx "github.com/tal-tech/go-zero/core/stringx"
"github.com/tal-tech/go-zero/tools/goctl/templatex"
"github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/tal-tech/go-zero/tools/goctl/util/console"
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
@@ -590,7 +589,7 @@ func (a *PbAst) GenTypesCode() (string, error) {
types = append(types, typeCode)
}
buffer, err := templatex.With("type").Parse(typeTemplate).Execute(map[string]interface{}{
buffer, err := util.With("type").Parse(typeTemplate).Execute(map[string]interface{}{
"types": strings.Join(types, util.NL+util.NL),
})
if err != nil {
@@ -615,7 +614,7 @@ func (s *Struct) genCode(containsTypeStatement bool) (string, error) {
comment = f.Comment[0]
}
doc = strings.Join(f.Document, util.NL)
buffer, err := templatex.With(sx.Rand()).Parse(fieldTemplate).Execute(map[string]interface{}{
buffer, err := util.With(sx.Rand()).Parse(fieldTemplate).Execute(map[string]interface{}{
"name": f.Name.Title(),
"type": f.Type.InvokeTypeExpression,
"tag": f.JsonTag,
@@ -630,7 +629,7 @@ func (s *Struct) genCode(containsTypeStatement bool) (string, error) {
fields = append(fields, buffer.String())
}
buffer, err := templatex.With("struct").Parse(structTemplate).Execute(map[string]interface{}{
buffer, err := util.With("struct").Parse(structTemplate).Execute(map[string]interface{}{
"type": containsTypeStatement,
"name": s.Name.Title(),
"fields": strings.Join(fields, util.NL),

View File

@@ -10,7 +10,6 @@ import (
"github.com/emicklei/proto"
"github.com/tal-tech/go-zero/core/collection"
"github.com/tal-tech/go-zero/core/lang"
"github.com/tal-tech/go-zero/tools/goctl/templatex"
"github.com/tal-tech/go-zero/tools/goctl/util"
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
)
@@ -263,7 +262,7 @@ func (e *Enum) GenEnumCode() (string, error) {
}
element = append(element, code)
}
buffer, err := templatex.With("enum").Parse(enumTemplate).Execute(map[string]interface{}{
buffer, err := util.With("enum").Parse(enumTemplate).Execute(map[string]interface{}{
"element": strings.Join(element, util.NL),
})
if err != nil {
@@ -273,7 +272,7 @@ func (e *Enum) GenEnumCode() (string, error) {
}
func (e *Enum) GenEnumTypeCode() (string, error) {
buffer, err := templatex.With("enumAlias").Parse(enumTypeTemplate).Execute(map[string]interface{}{
buffer, err := util.With("enumAlias").Parse(enumTypeTemplate).Execute(map[string]interface{}{
"name": e.Name.Source(),
})
if err != nil {
@@ -283,7 +282,7 @@ func (e *Enum) GenEnumTypeCode() (string, error) {
}
func (e *EnumField) GenEnumFieldCode(parentName string) (string, error) {
buffer, err := templatex.With("enumField").Parse(enumFiledTemplate).Execute(map[string]interface{}{
buffer, err := util.With("enumField").Parse(enumFiledTemplate).Execute(map[string]interface{}{
"key": e.Key,
"name": parentName,
"value": e.Value,