feat: use go:embed to embed templates (#1756)
This commit is contained in:
@@ -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)
|
||||
|
||||
16
tools/goctl/api/docgen/markdown.tpl
Normal file
16
tools/goctl/api/docgen/markdown.tpl
Normal 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}}
|
||||
Reference in New Issue
Block a user