feat: 重构路由渲染逻辑,添加构建渲染数据和模板渲染功能,优化代码结构

This commit is contained in:
Rogee
2025-09-11 19:14:44 +08:00
parent a23e31fea3
commit 344798163b
4 changed files with 174 additions and 104 deletions

23
pkg/ast/route/renderer.go Normal file
View 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
}