Skip to content

Commit

Permalink
Addressed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ampant committed Sep 17, 2019
1 parent f8876ce commit 6b1130d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/custom-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
10 changes: 4 additions & 6 deletions internal/configs/version1/template_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 0 additions & 2 deletions internal/configs/version1/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 6b1130d

Please sign in to comment.