mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-31 18:05:48 +08:00
feat: 代码优化、机器计划任务完善
This commit is contained in:
28
server/pkg/utils/stringx/template.go
Normal file
28
server/pkg/utils/stringx/template.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package stringx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func parse(t *template.Template, vars any) string {
|
||||
var tmplBytes bytes.Buffer
|
||||
|
||||
err := t.Execute(&tmplBytes, vars)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tmplBytes.String()
|
||||
}
|
||||
|
||||
// 模板字符串解析
|
||||
// @param str 模板字符串
|
||||
// @param vars 参数变量
|
||||
func TemplateParse(str string, vars any) string {
|
||||
tmpl, err := template.New("tmpl").Parse(str)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return parse(tmpl, vars)
|
||||
}
|
||||
Reference in New Issue
Block a user