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

@@ -7,7 +7,6 @@ import (
"github.com/tal-tech/go-zero/core/collection"
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
"github.com/tal-tech/go-zero/tools/goctl/templatex"
"github.com/tal-tech/go-zero/tools/goctl/util"
)
@@ -62,7 +61,7 @@ func (g *defaultRpcGenerator) genLogic() error {
svcImport := fmt.Sprintf(`"%v"`, g.mustGetPackage(dirSvc))
imports.AddStr(svcImport)
imports.AddStr(importList...)
err = templatex.With("logic").GoFmt(true).Parse(logicTemplate).SaveTo(map[string]interface{}{
err = util.With("logic").GoFmt(true).Parse(logicTemplate).SaveTo(map[string]interface{}{
"logicName": fmt.Sprintf("%sLogic", method.Name.Title()),
"functions": functions,
"imports": strings.Join(imports.KeysStr(), util.NL),
@@ -83,7 +82,7 @@ func (g *defaultRpcGenerator) genLogicFunction(packageName string, method *parse
}
imports.AddStr(g.ast.Imports[method.ParameterIn.Package])
imports.AddStr(g.ast.Imports[method.ParameterOut.Package])
buffer, err := templatex.With("fun").Parse(logicFunctionTemplate).Execute(map[string]interface{}{
buffer, err := util.With("fun").Parse(logicFunctionTemplate).Execute(map[string]interface{}{
"logicName": fmt.Sprintf("%sLogic", method.Name.Title()),
"method": method.Name.Title(),
"request": method.ParameterIn.StarExpression,