Skip to content

Commit adfae4c

Browse files
committed
add TrimPrefix, ToUpper, and ToLower templapte funcs
We need TrimPrefix and ToUpper for some links at Tailscale, and might as well ToLower as well at that point. Updates #10 Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <[email protected]>
1 parent 701c466 commit adfae4c

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

golink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ func (e expandEnv) User() (string, error) {
651651
var expandFuncMap = texttemplate.FuncMap{
652652
"PathEscape": url.PathEscape,
653653
"QueryEscape": url.QueryEscape,
654+
"TrimPrefix": strings.TrimPrefix,
654655
"TrimSuffix": strings.TrimSuffix,
655656
"Match": regexMatch,
656657
}

golink_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ func TestExpandLink(t *testing.T) {
411411
remainder: "a/b+c",
412412
want: "http://host.com/a%2Fb%2Bc",
413413
},
414+
{
415+
name: "template-with-trimprefix-func",
416+
long: `http://host.com/{{TrimPrefix .Path "BUG-"}}`,
417+
remainder: "BUG-123",
418+
want: "http://host.com/123",
419+
},
414420
{
415421
name: "template-with-trimsuffix-func",
416422
long: `http://host.com/{{TrimSuffix .Path "/"}}`,

tmpl/help.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ <h2 id="advanced">Advanced destination links</h2>
6363
<ul>
6464
<li><code>PathEscape</code> is the <a href="https://pkg.go.dev/net/url#PathEscape">url.PathEscape</a> function for escaping values inside a URL path.
6565
<li><code>QueryEscape</code> is the <a href="https://pkg.go.dev/net/url#QueryEscape">url.QueryEscape</a> function for escaping values inside a URL query.
66+
<li><code>TrimPrefix</code> is the <a href="https://pkg.go.dev/strings#TrimPrefix">strings.TrimPrefix</a> function for removing a leading prefix.
6667
<li><code>TrimSuffix</code> is the <a href="https://pkg.go.dev/strings#TrimSuffix">strings.TrimSuffix</a> function for removing a trailing suffix.
6768
<li><code>Match</code> is the <a href="https://pkg.go.dev/regexp#MatchString">regexp.MatchString</a> function for matching a regular expression pattern.
6869
</ul>

0 commit comments

Comments
 (0)