format: add string functions

This commit is contained in:
Filippo Giunchedi 2020-10-28 17:49:49 +01:00
parent 767cb9fb8e
commit 1eb6c5e397
1 changed files with 8 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
"bytes"
"encoding/json"
"log"
"strings"
"text/template"
promtmpl "github.com/prometheus/alertmanager/template"
@ -29,7 +30,13 @@ type Formatter struct {
}
func NewFormatter(config *Config) (*Formatter, error) {
tmpl, err := template.New("msg").Parse(config.MsgTemplate)
funcMap := template.FuncMap{
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
"Join": strings.Join,
}
tmpl, err := template.New("msg").Funcs(funcMap).Parse(config.MsgTemplate)
if err != nil {
return nil, err
}