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"
"strings"
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
@@ -8,27 +9,8 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/util/format"
)
var middlewareImplementCode = `
package middleware
import "net/http"
type {{.name}} struct {
}
func New{{.name}}() *{{.name}} {
return &{{.name}}{}
}
func (m *{{.name}})Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO generate middleware implement function, delete after code implementation
// Passthrough to next handler if need
next(w, r)
}
}
`
//go:embed middleware.tpl
var middlewareImplementCode string
func genMiddleware(dir string, cfg *config.Config, api *spec.ApiSpec) error {
middlewares := getMiddleware(api)