From 6003cdbae04d82bd55bbd8c6481ea5200ac9aa6d Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 5 Jun 2014 18:44:19 +0100 Subject: [PATCH] Add title and match functions. Change-Id: Ifd376c2935e22d378e7afa06122642847a237d78 --- templates/templates.go | 3 +++ templates/templates_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/templates/templates.go b/templates/templates.go index f4614fd75..479427466 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -20,6 +20,7 @@ import ( "math" "regexp" "sort" + "strings" "text/template" clientmodel "github.com/prometheus/client_golang/model" @@ -92,6 +93,8 @@ func Expand(text string, name string, data interface{}, timestamp clientmodel.Ti re := regexp.MustCompile(pattern) return re.ReplaceAllString(text, repl) }, + "match": regexp.MatchString, + "title": strings.Title, "sortByLabel": func(label string, v queryResult) queryResult { sorter := queryResultByLabelSorter{v[:], label} sort.Stable(sorter) diff --git a/templates/templates_test.go b/templates/templates_test.go index eaf124bc2..1de164589 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -89,6 +89,16 @@ func TestTemplateExpansion(t *testing.T) { text: "{{ 0.0 | humanize1024 }}:{{ 1.0 | humanize1024 }}:{{ 1048576.0 | humanize1024 }}:{{ .12 | humanize1024}}", output: "0 :1 :1 Mi:0.12 ", }, + { + // Title. + text: "{{ \"aa bb CC\" | title }}", + output: "Aa Bb CC", + }, + { + // Match. + text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}", + output: "true false", + }, } time := clientmodel.Timestamp(0)