diff --git a/golink.go b/golink.go index d31f816..3bc3353 100644 --- a/golink.go +++ b/golink.go @@ -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 diff --git a/golink_test.go b/golink_test.go index 955aff7..f00a584 100644 --- a/golink_test.go +++ b/golink_test.go @@ -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) {