feat: use go:embed to embed templates (#1756)

This commit is contained in:
Kevin Wan
2022-04-04 13:12:05 +08:00
committed by GitHub
parent 58a0b17451
commit faad6e27e3
60 changed files with 739 additions and 691 deletions

View File

@@ -1,6 +1,7 @@
package gogen
import (
_ "embed"
"fmt"
"path"
"strconv"
@@ -14,32 +15,8 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/vars"
)
const logicTemplate = `package {{.pkgName}}
import (
{{.imports}}
)
type {{.logic}} struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} {
return &{{.logic}}{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *{{.logic}}) {{.function}}({{.request}}) {{.responseType}} {
// todo: add your logic here and delete this line
{{.returnString}}
}
`
//go:embed logic.tpl
var logicTemplate string
func genLogic(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
for _, g := range api.Service.Groups {