This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user