Skip to content

Commit

Permalink
add TrimSuffix to the function map (#10)
Browse files Browse the repository at this point in the history
Adds strings.TrimSuffix to the function map, enabling it to be used in URL definitions.
  • Loading branch information
vielmetti authored Dec 1, 2022
1 parent f07445b commit 0755e37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions golink.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ type expandEnv struct {
var expandFuncMap = texttemplate.FuncMap{
"PathEscape": url.PathEscape,
"QueryEscape": url.QueryEscape,
"TrimSuffix": strings.TrimSuffix,
}

// expandLink returns the expanded long URL to redirect to, executing any
Expand Down
6 changes: 6 additions & 0 deletions golink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func TestExpandLink(t *testing.T) {
remainder: "a+b",
want: "http://host.com/a%2Bb",
},
{
name: "template-with-trimsuffix-func",
long: `http://host.com/{{TrimSuffix .Path "/"}}`,
remainder: "a/",
want: "http://host.com/a",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 0755e37

Please sign in to comment.