Skip to content

Commit

Permalink
Add link to Templates wiki entry
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Nov 4, 2013
1 parent f289a8a commit 3497f64
Showing 1 changed file with 1 addition and 54 deletions.
55 changes: 1 addition & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,7 @@ See [Template Resources](https://github.com/kelseyhightower/confd/wiki/Template-

## Templates

Templates define a single application configration template.
Templates are stored under the `confdir/templates` directory.

Templates are written in Go's [`text/template`](http://golang.org/pkg/text/template/).

Etcd keys are treated as paths and automatically transformed into keys for retrieval in templates. Underscores are used in place of forward slashes. _Values retrived from Etcd are never modified._
For example `/foo/bar` becomes `foo_bar`.

`foo_bar` is accessed as `{{ .foo_bar }}`


Example:
```
$ etcdctl set /nginx/domain 'example.com'
$ etcdctl set /nginx/root '/var/www/example_dotcom'
$ etcdctl set /nginx/worker_processes '2'
```


`$ cat /etc/confd/templates/nginx.conf.tmpl`:
```
worker_processes {{ .nginx_worker_processes }};
server {
listen 80;
server_name www.{{ .nginx_domain }};
access_log /var/log/nginx/{{ .nginx_domain }}.access.log;
error_log /var/log/nginx/{{ .nginx_domain }}.log;
location / {
root {{ .nginx_root }};
index index.html index.htm;
}
}
```

Will produce `/etc/nginx/nginx.conf`:
```
worker_processes 2;
server {
listen 80;
server_name www.example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location / {
root /var/www/example_dotcom;
index index.html index.htm;
}
}
```

Go's [`text/template`](http://golang.org/pkg/text/template/) package is very powerful. For more details on it's capabilities see its [documentation.](http://golang.org/pkg/text/template/)
See [Templates](https://github.com/kelseyhightower/confd/wiki/Templates)

## Extras

Expand Down

0 comments on commit 3497f64

Please sign in to comment.