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.
23 lines
376 B
23 lines
376 B
2 months ago
|
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
|
||
|
}
|