mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-26 16:12:20 +00:00
Make TrimSpace available for use in the template (#3281)
* Make TrimSpace available for use in the template Signed-off-by: Ghazanfar <ghazanfar.isc@gmail.com>
This commit is contained in:
parent
41eb1213bb
commit
d8bea84adc
@ -89,6 +89,7 @@ templating.
|
||||
| title | string |[strings.Title](http://golang.org/pkg/strings/#Title), capitalises first character of each word. |
|
||||
| toUpper | string | [strings.ToUpper](http://golang.org/pkg/strings/#ToUpper), converts all characters to upper case. |
|
||||
| toLower | string | [strings.ToLower](http://golang.org/pkg/strings/#ToLower), converts all characters to lower case. |
|
||||
| trimSpace | string | [strings.TrimSpace](https://pkg.go.dev/strings#TrimSpace), removes leading and trailing white spaces. |
|
||||
| match | pattern, string | [Regexp.MatchString](https://golang.org/pkg/regexp/#MatchString). Match a string using Regexp. |
|
||||
| reReplaceAll | pattern, replacement, text | [Regexp.ReplaceAllString](http://golang.org/pkg/regexp/#Regexp.ReplaceAllString) Regexp substitution, unanchored. |
|
||||
| join | sep string, s []string | [strings.Join](http://golang.org/pkg/strings/#Join), concatenates the elements of s to create a single string. The separator string sep is placed between elements in the resulting string. (note: argument order inverted for easier pipelining in templates.) |
|
||||
|
@ -168,9 +168,11 @@ func (t *Template) ExecuteHTMLString(html string, data interface{}) (string, err
|
||||
type FuncMap map[string]interface{}
|
||||
|
||||
var DefaultFuncs = FuncMap{
|
||||
"toUpper": strings.ToUpper,
|
||||
"toLower": strings.ToLower,
|
||||
"title": cases.Title(language.AmericanEnglish).String,
|
||||
"toUpper": strings.ToUpper,
|
||||
"toLower": strings.ToLower,
|
||||
"trimSpace": strings.TrimSpace,
|
||||
|
||||
"title": cases.Title(language.AmericanEnglish).String,
|
||||
// join is equal to strings.Join but inverts the argument order
|
||||
// for easier pipelining in templates.
|
||||
"join": func(sep string, s []string) string {
|
||||
|
@ -328,6 +328,11 @@ func TestTemplateExpansion(t *testing.T) {
|
||||
in: `{{ "abc" | title }}`,
|
||||
exp: "Abc",
|
||||
},
|
||||
{
|
||||
title: "Template using TrimSpace",
|
||||
in: `{{ " a b c " | trimSpace }}`,
|
||||
exp: "a b c",
|
||||
},
|
||||
{
|
||||
title: "Template using positive match",
|
||||
in: `{{ if match "^a" "abc"}}abc{{ end }}`,
|
||||
|
Loading…
Reference in New Issue
Block a user