support api templates

This commit is contained in:
kevin
2020-10-15 16:36:49 +08:00
parent 8291eabc2c
commit f904710811
32 changed files with 274 additions and 155 deletions

View File

@@ -12,6 +12,7 @@ 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"
@@ -589,7 +590,7 @@ func (a *PbAst) GenTypesCode() (string, error) {
types = append(types, typeCode)
}
buffer, err := util.With("type").Parse(typeTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With("type").Parse(typeTemplate).Execute(map[string]interface{}{
"types": strings.Join(types, util.NL+util.NL),
})
if err != nil {
@@ -614,7 +615,7 @@ func (s *Struct) genCode(containsTypeStatement bool) (string, error) {
comment = f.Comment[0]
}
doc = strings.Join(f.Document, util.NL)
buffer, err := util.With(sx.Rand()).Parse(fieldTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With(sx.Rand()).Parse(fieldTemplate).Execute(map[string]interface{}{
"name": f.Name.Title(),
"type": f.Type.InvokeTypeExpression,
"tag": f.JsonTag,
@@ -629,7 +630,7 @@ func (s *Struct) genCode(containsTypeStatement bool) (string, error) {
fields = append(fields, buffer.String())
}
buffer, err := util.With("struct").Parse(structTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With("struct").Parse(structTemplate).Execute(map[string]interface{}{
"type": containsTypeStatement,
"name": s.Name.Title(),
"fields": strings.Join(fields, util.NL),

View File

@@ -10,6 +10,7 @@ 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"
)
@@ -262,7 +263,7 @@ func (e *Enum) GenEnumCode() (string, error) {
}
element = append(element, code)
}
buffer, err := util.With("enum").Parse(enumTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With("enum").Parse(enumTemplate).Execute(map[string]interface{}{
"element": strings.Join(element, util.NL),
})
if err != nil {
@@ -272,7 +273,7 @@ func (e *Enum) GenEnumCode() (string, error) {
}
func (e *Enum) GenEnumTypeCode() (string, error) {
buffer, err := util.With("enumAlias").Parse(enumTypeTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With("enumAlias").Parse(enumTypeTemplate).Execute(map[string]interface{}{
"name": e.Name.Source(),
})
if err != nil {
@@ -282,7 +283,7 @@ func (e *Enum) GenEnumTypeCode() (string, error) {
}
func (e *EnumField) GenEnumFieldCode(parentName string) (string, error) {
buffer, err := util.With("enumField").Parse(enumFiledTemplate).Execute(map[string]interface{}{
buffer, err := templatex.With("enumField").Parse(enumFiledTemplate).Execute(map[string]interface{}{
"key": e.Key,
"name": parentName,
"value": e.Value,