diff --git a/docs/custom-annotations.md b/docs/custom-annotations.md index f23523561f..2e40fb65a4 100644 --- a/docs/custom-annotations.md +++ b/docs/custom-annotations.md @@ -92,8 +92,8 @@ Helper functions can be used in the Ingress template to parse the values of cust | Function | Input Arguments| Return Arguments | Description | | -------- | -------------- | ---------------- | ----------- | -| `split` | s, sep string | []string | Splits the string s into a slice of strings separated by the sep. | -| `trim` | s string | string | Trims the trailing and leading whitespace from the string s. | +| `split` | `s, sep string` | `[]string` | Splits the string `s` into a slice of strings separated by the `sep`. | +| `trim` | `s string` | `string` | Trims the trailing and leading whitespace from the string `s`. | Consider the following custom annotation `custom.nginx.org/allowed-ips`, which expects a comma-separated list of IP addresses: ``` diff --git a/internal/configs/version1/template_helper.go b/internal/configs/version1/template_helper.go index cce493e2bb..c2b09f5c61 100644 --- a/internal/configs/version1/template_helper.go +++ b/internal/configs/version1/template_helper.go @@ -5,17 +5,15 @@ import ( "text/template" ) -// splitinput splits the input from "," and returns an array of strings -func splitinput(s string, delim string) []string { +func split(s string, delim string) []string { return strings.Split(s, delim) } -// triminput trims the leading and trailing spaces in the string -func triminput(s string) string { +func trim(s string) string { return strings.TrimSpace(s) } var helperFunctions = template.FuncMap{ - "split": splitinput, //returns array of strings - "trim": triminput, //returns string with trimmed leading and trailing spaces + "split": split, + "trim": trim, } diff --git a/internal/configs/version1/templates_test.go b/internal/configs/version1/templates_test.go index 62340ab6d5..8a863dcc7c 100644 --- a/internal/configs/version1/templates_test.go +++ b/internal/configs/version1/templates_test.go @@ -184,7 +184,6 @@ func TestSplitHelperFunction(t *testing.T) { expected := "foo bar " err = tmpl.Execute(&buf, input) - t.Log(buf.String()) if err != nil { t.Fatalf("Failed to execute the template %v", err) } @@ -208,7 +207,6 @@ func TestTrimHelperFunction(t *testing.T) { expected := "foobar" err = tmpl.Execute(&buf, input) - t.Log(buf.String()) if err != nil { t.Fatalf("Failed to execute the template %v", err) }