Skip to content

Commit

Permalink
Merge pull request kelseyhightower#160 from kelseyhightower/add-exist…
Browse files Browse the repository at this point in the history
…-function

template: add exists function
  • Loading branch information
kelseyhightower committed Oct 26, 2014
2 parents 7b29dbb + 80afff1 commit 0649a6c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

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

22 changes: 16 additions & 6 deletions Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go

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

10 changes: 10 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Alias for the path.Base function.
{{end}}
```

### exists

Checks if the key exists. Return false if key is not found.

```
{{if exists "/key"}}
value: {{getv "/key"}}
{{end}}
```

### get

Returns the KVPair where key matches its argument. Returns an error if key is not found.
Expand Down
7 changes: 7 additions & 0 deletions integration/confdir/conf.d/exists.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[template]
mode = "0644"
src = "exists-test.conf.tmpl"
dest = "/tmp/confd-exists-test.conf"
keys = [
"/key",
]
8 changes: 8 additions & 0 deletions integration/confdir/templates/exists-test.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{if exists "/key"}}
value: {{getv "/key"}}
{{end}}

{{if exists "/doesnotexist"}}
This line will not be printed
value: {{getv "/key"}}
{{end}}
1 change: 1 addition & 0 deletions integration/etcd/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

curl -L -X PUT http://127.0.0.1:4001/v2/keys/key -d value=foobar
curl -L -X PUT http://127.0.0.1:4001/v2/keys/database/host -d value=127.0.0.1
curl -L -X PUT http://127.0.0.1:4001/v2/keys/database/password -d value=p@sSw0rd
curl -L -X PUT http://127.0.0.1:4001/v2/keys/database/port -d value=3306
Expand Down

0 comments on commit 0649a6c

Please sign in to comment.