修复模板注入问题

This commit is contained in:
dragon
2025-04-15 17:38:45 +08:00
parent 3f63988e2d
commit 2e7e301858
3 changed files with 14 additions and 8 deletions

View File

@@ -1,8 +1,10 @@
package utils
import (
sprig "github.com/go-task/slim-sprig/v3"
"net/http"
"strings"
"text/template"
)
func NewTemplateInject(r *http.Request, def map[string]any) map[string]any {
@@ -23,3 +25,7 @@ func NewTemplateInject(r *http.Request, def map[string]any) map[string]any {
}
return def
}
func NewTemplate(data string) *template.Template {
return template.Must(template.New("err").Funcs(sprig.FuncMap()).Parse(data))
}