数据 输入输出 处理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
376 B

package utils
import (
"strings"
"text/template"
)
func TextTemplateMatch(obj any, textTemplate string) (string, error) {
// 定义模板字符串
tmpl, err := template.New("template").Parse(textTemplate)
if err != nil {
panic(err)
}
sb := strings.Builder{}
err = tmpl.Execute(&sb, obj)
if err != nil {
return "", err
}
sbs := sb.String()
return sbs, err
}