Skip to content

Commit

Permalink
Add template functions (#110)
Browse files Browse the repository at this point in the history
JacobValdemar authored Nov 24, 2023
1 parent b009ef3 commit d8ded4b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion template.go
Original file line number Diff line number Diff line change
@@ -20,8 +20,13 @@ func BotMessage(data BotMessageData) (string, error) {
return "", errors.New("template is empty")
}

templateFuncs := template.FuncMap{
"contains": strings.Contains,
"replaceAll": strings.ReplaceAll,
}

template := template.New("test")
template, err := template.Parse(data.Template)
template, err := template.Funcs(templateFuncs).Parse(data.Template)
if err != nil {
return "", errors.Wrapf(err, "parsing template: '%s'", data.Template)
}

0 comments on commit d8ded4b

Please sign in to comment.