Skip to content

Commit 0755e37

Browse files
authored
add TrimSuffix to the function map (#10)
Adds strings.TrimSuffix to the function map, enabling it to be used in URL definitions.
1 parent f07445b commit 0755e37

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

golink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ type expandEnv struct {
353353
var expandFuncMap = texttemplate.FuncMap{
354354
"PathEscape": url.PathEscape,
355355
"QueryEscape": url.QueryEscape,
356+
"TrimSuffix": strings.TrimSuffix,
356357
}
357358

358359
// expandLink returns the expanded long URL to redirect to, executing any

golink_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ func TestExpandLink(t *testing.T) {
6868
remainder: "a+b",
6969
want: "http://host.com/a%2Bb",
7070
},
71+
{
72+
name: "template-with-trimsuffix-func",
73+
long: `http://host.com/{{TrimSuffix .Path "/"}}`,
74+
remainder: "a/",
75+
want: "http://host.com/a",
76+
},
7177
}
7278
for _, tt := range tests {
7379
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)