Skip to content

Commit

Permalink
getv accepts a default value
Browse files Browse the repository at this point in the history
The `getv` template function does not accept a default value. The
workaround is to write templates like this:

    {{if exists "/example/app/option"}}
    option = {{getv "/example/app/option"}}{{else}}default_value{{end}}

Resolve the issue by accepting an optional default value. Templates
can now be written like this:

    value: {{getv "/key" "default_value"}}

This change is backwards compatible with the current `getv` function.
If the key is missing and a default value is given the missing key error
will be suppressed and the default value will be returned.

If the key is missing and no default value is given the `getv` function
will return an error and template processing will halt.

Fixes #219
  • Loading branch information
kelseyhightower committed Feb 24, 2016
1 parent 710bf63 commit 4388e4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
5 changes: 4 additions & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ Returns all KVPair, []KVPair, where key matches its argument. Returns an error i

### getv

Returns the value as a string where key matches its argument. Returns an error if key is not found.
Returns the value as a string where key matches its argument or an optional default value.
Returns an error if key is not found and no default value given.

```
value: {{getv "/key"}}
```

#### With a default value

```
value: {{getv "/key" "default_value"}}
```

### getvs

Returns all values, []string, where key matches its argument. Returns an error if key is not found.
Expand Down
38 changes: 0 additions & 38 deletions vendor/github.com/coreos/etcd/pkg/pathutil/path_test.go

This file was deleted.

10 changes: 9 additions & 1 deletion vendor/github.com/kelseyhightower/memkv/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4388e4b

Please sign in to comment.