Skip to content

Commit

Permalink
add TrimPrefix method to go along with TrimSuffix
Browse files Browse the repository at this point in the history
Updates #10

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <will@tailscale.com>
  • Loading branch information
willnorris committed Sep 19, 2024
1 parent 701c466 commit 8545e9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions golink.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ func (e expandEnv) User() (string, error) {
var expandFuncMap = texttemplate.FuncMap{
"PathEscape": url.PathEscape,
"QueryEscape": url.QueryEscape,
"TrimPrefix": strings.TrimPrefix,
"TrimSuffix": strings.TrimSuffix,
"Match": regexMatch,
}
Expand Down
6 changes: 6 additions & 0 deletions golink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ func TestExpandLink(t *testing.T) {
remainder: "a/b+c",
want: "http://host.com/a%2Fb%2Bc",
},
{
name: "template-with-trimprefix-func",
long: `http://host.com/{{TrimPrefix .Path "BUG-"}}`,
remainder: "BUG-123",
want: "http://host.com/123",
},
{
name: "template-with-trimsuffix-func",
long: `http://host.com/{{TrimSuffix .Path "/"}}`,
Expand Down
1 change: 1 addition & 0 deletions tmpl/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h2 id="advanced">Advanced destination links</h2>
<ul>
<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.
<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.
<li><code>TrimPrefix</code> is the <a href="https://pkg.go.dev/strings#TrimPrefix">strings.TrimPrefix</a> function for removing a leading prefix.
<li><code>TrimSuffix</code> is the <a href="https://pkg.go.dev/strings#TrimSuffix">strings.TrimSuffix</a> function for removing a trailing suffix.
<li><code>Match</code> is the <a href="https://pkg.go.dev/regexp#MatchString">regexp.MatchString</a> function for matching a regular expression pattern.
</ul>
Expand Down

0 comments on commit 8545e9b

Please sign in to comment.