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

@@ -2,6 +2,7 @@ package docgen
import (
"bytes"
_ "embed"
"fmt"
"html/template"
"strconv"
@@ -13,25 +14,8 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/api/util"
)
const (
markdownTemplate = `
### {{.index}}. {{.routeComment}}
1. 路由定义
- Url: {{.uri}}
- Method: {{.method}}
- Request: {{.requestType}}
- Response: {{.responseType}}
2. 请求定义
{{.requestContent}}
3. 返回定义
{{.responseContent}}
`
)
//go:embed markdown.tpl
var markdownTemplate string
func genDoc(api *spec.ApiSpec, dir, filename string) error {
fp, _, err := util.MaybeCreateFile(dir, "", filename)

View File

@@ -0,0 +1,16 @@
### {{.index}}. {{.routeComment}}
1. route definition
- Url: {{.uri}}
- Method: {{.method}}
- Request: {{.requestType}}
- Response: {{.responseType}}
2. request definition
{{.requestContent}}
3. response definition
{{.responseContent}}