Skip to content

Commit

Permalink
document the base template function
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Jul 9, 2014
1 parent 5fed4ea commit ee08724
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Templates are written in Go's [`text/template`](http://golang.org/pkg/text/templ

## Template Functions

### base

Alias for the path.Base function.

```
{{with get "/key"}}
key: {{base .Key}}
value: {{.Value}}
{{end}}
```

### get

Returns the KVPair where key matches its argument.
Expand Down
1 change: 1 addition & 0 deletions integration/confdir/conf.d/basic.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[template]
mode = "0644"
src = "basic.conf.tmpl"
dest = "/tmp/confd-basic-test.conf"
Expand Down
1 change: 1 addition & 0 deletions integration/confdir/conf.d/iteration.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[template]
mode = "0644"
src = "iteration.conf.tmpl"
dest = "/tmp/confd-iteration-test.conf"
Expand Down
4 changes: 2 additions & 2 deletions integration/confdir/templates/iteration.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
upstream app {
{{range getvs "/upstream/*"}}
server {{.}};
{{range gets "/upstream/*"}}
server {{.Value}};
{{end}}
}

Expand Down
2 changes: 1 addition & 1 deletion integration/etcd/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ curl -L -X PUT http://127.0.0.1:4001/v2/keys/prefix/upstream/app2 -d value=10.0.


# Run confd
./confd -verbose -onetime -confdir ./integration/confdir -backend etcd -node 127.0.0.1:4001
./confd -verbose -debug -onetime -confdir ./integration/confdir -backend etcd -node 127.0.0.1:4001
1 change: 1 addition & 0 deletions resource/template/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (t *TemplateResource) createStageFile() error {

// Add template functions
tplFuncMap := make(template.FuncMap)
tplFuncMap["base"] = path.Base
tplFuncMap["get"] = t.store.Get
tplFuncMap["gets"] = t.store.GetAll
tplFuncMap["getv"] = t.store.GetValue
Expand Down

0 comments on commit ee08724

Please sign in to comment.