🐛修复模板渲染bug
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
coward
2024-08-20 14:24:13 +08:00
parent af76eda4bc
commit 941b8da804
3 changed files with 18 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import (
"gitee.ltd/lxh/logger/log"
"html/template"
"os"
"strings"
)
type TemplateComponent struct{}
@@ -47,7 +48,7 @@ func (t TemplateComponent) ParseTemplate(filepath string) (tp *template.Template
return
}
tp, err = template.New("wg.conf").Parse(string(file))
tp, err = template.New("wg.conf").Funcs(t.FuncMap()).Parse(string(file))
return
}
@@ -74,3 +75,18 @@ func (t TemplateComponent) Render(tp *template.Template, data any, filepath stri
return tp.Execute(wg0Conf, data)
}
// FuncMap
// @description: 模板内的操作方法
// @receiver t
// @return template.FuncMap
// @return error
func (t TemplateComponent) FuncMap() template.FuncMap {
sliceToString := func(str []string) string {
return strings.Join(str, ",")
}
return template.FuncMap{
"sliceToStr": sliceToString,
}
}