feat: use go:embed to embed templates (#1756)
This commit is contained in:
3
tools/goctl/api/tsgen/components.tpl
Normal file
3
tools/goctl/api/tsgen/components.tpl
Normal file
@@ -0,0 +1,3 @@
|
||||
/ Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
{{.componentTypes}}
|
||||
@@ -1,6 +1,7 @@
|
||||
package tsgen
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"path"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -10,12 +11,8 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
const (
|
||||
componentsTemplate = `// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
{{.componentTypes}}
|
||||
`
|
||||
)
|
||||
//go:embed components.tpl
|
||||
var componentsTemplate string
|
||||
|
||||
func genComponents(dir string, api *spec.ApiSpec) error {
|
||||
types := api.Types
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tsgen
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -12,12 +13,8 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
const (
|
||||
handlerTemplate = `{{.imports}}
|
||||
|
||||
{{.apis}}
|
||||
`
|
||||
)
|
||||
//go:embed handler.tpl
|
||||
var handlerTemplate string
|
||||
|
||||
func genHandler(dir, webAPI, caller string, api *spec.ApiSpec, unwrapAPI bool) error {
|
||||
filename := strings.Replace(api.Service.Name, "-api", "", 1) + ".ts"
|
||||
|
||||
3
tools/goctl/api/tsgen/handler.tpl
Normal file
3
tools/goctl/api/tsgen/handler.tpl
Normal file
@@ -0,0 +1,3 @@
|
||||
{{.imports}}
|
||||
|
||||
{{.apis}}
|
||||
Reference in New Issue
Block a user