feat: 重构路由渲染逻辑,添加构建渲染数据和模板渲染功能,优化代码结构
This commit is contained in:
23
pkg/ast/route/renderer.go
Normal file
23
pkg/ast/route/renderer.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
)
|
||||
|
||||
var routerTmpl = template.Must(template.New("route").
|
||||
Funcs(sprig.FuncMap()).
|
||||
Option("missingkey=error").
|
||||
Parse(routeTpl),
|
||||
)
|
||||
|
||||
func renderTemplate(data RenderData) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := routerTmpl.Execute(&buf, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user