Skip to content

Commit

Permalink
Add urlParse function (i.e. url.Parse)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
  • Loading branch information
hairyhenderson committed May 2, 2017
1 parent 3434806 commit ba9432d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,27 @@ $ FOO=" world " | gomplate < input.tmpl
Hello, world!
```

#### `urlParse`

Parses a string as a URL for later use. Equivalent to [url.Parse](https://golang.org/pkg/net/url/#Parse)

##### Example

_`input.tmpl`:_
```
{{ $u := urlParse "https://example.com:443/foo/bar" }}
The scheme is {{ $u.Scheme }}
The host is {{ $u.Host }}
The path is {{ $u.Path }}
```

```console
$ gomplate < input.tmpl
The scheme is https
The host is example.com:443
The path is /foo/bar
```

#### `has`

Has reports whether or not a given object has a property with the given key. Can be used with `if` to prevent the template from trying to access a non-existent property in an object.
Expand Down
2 changes: 2 additions & 0 deletions gomplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"io"
"log"
"net/url"

"strings"
"text/template"
Expand Down Expand Up @@ -68,6 +69,7 @@ func NewGomplate(data *Data, leftDelim, rightDelim string) *Gomplate {
"toLower": strings.ToLower,
"trim": strings.Trim,
"trimSpace": strings.TrimSpace,
"urlParse": url.Parse,
"datasource": data.Datasource,
"ds": data.Datasource,
"datasourceExists": data.DatasourceExists,
Expand Down

0 comments on commit ba9432d

Please sign in to comment.