function arg1 arg2…, and pipelines draw on the UNIX concept of chaining together a series of template commands to express a series of transformations separated by a “pipe” (|) character.
An example combining functions and pipelines together looks like this:
"PROD".
All the standard Go template actions, functions, and a dozen or so additional template functions are available for use when authoring templates.
date
date formats a timestamp:
2024-11-22. Useful in conjunction with .Alert.Timestamp
join
join joins a list of things into a single string with the provided separator:
group1,group2,group3.
lower
lower converts the entire string to lowercase:
hello.
now
now returns the current time at the time of template execution. Most useful with date.
quote
quote wraps the string in double quotes:
"prod" assuming the value of ”.Environment” is prod.
sort
sort sorts a list of strings into alphabetical (lexicographical) order:
[apple banana orange].
split
split splits a string into a list of strings:
[one two three].
toJson
toJson encodes an item into a JSON string.
If the item cannot be converted to JSON, then the function returns an empty string.
["apple", "banana", "orange"].
trim
trim removes whitespace from either side of a string:
hello.
trunc
trunc truncates a string by a specified number of characters:
hello.
world.
upper
upper converts the entire string to uppercase:
HELLO.
duration
duration formats a given amount of seconds in human-readable time:
1m35s.