Skip to content

Commit

Permalink
updated template docs
Browse files Browse the repository at this point in the history
  • Loading branch information
odedlaz committed Mar 7, 2016
1 parent 6bb3c21 commit 27783ef
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ Templates are written in Go's [`text/template`](http://golang.org/pkg/text/templ

## Template Functions

### map

creates a key-value map of string -> interface{}

```
{{$endpoint := map "name" "elasticsearch" "private_port" 9200 "public_port" 443}}
name: {{index $endpoint "name"}}
private-port: {{index $endpoint "private_port"}}
public-port: {{index $endpoint "public_port"}}
```

specifically useful if you a sub-template and you want to pass multiple values to it.

### base

Alias for the path.Base function.
Alias for the [path.Base](https://golang.org/pkg/path/#Base) function.

```
{{with get "/key"}}
Expand Down Expand Up @@ -77,7 +91,7 @@ Returns all values, []string, where key matches its argument. Returns an error i

### getenv

Alias for os.Getenv
Wrapper for [os.Getenv](https://golang.org/pkg/os/#Getenv). Retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. Optionally, you can give a default value that will be returned if the key is not present.

```
export HOSTNAME=`hostname`
Expand All @@ -87,9 +101,16 @@ export HOSTNAME=`hostname`
hostname: {{getenv "HOSTNAME"}}
```


#### With a default value

```
ipaddr: {{getenv "HOST_IP" "127.0.0.1"}}
```

### datetime

Alias for time.Now
Alias for [time.Now](https://golang.org/pkg/time/#Now)

```
# Generated by confd {{datetime}}
Expand Down Expand Up @@ -252,7 +273,7 @@ dir: {{.}}

### join

Alias for the strings.Join function.
Alias for the [strings.Join](https://golang.org/pkg/strings/#Join) function.

```
{{$services := getvs "/services/elasticsearch/*"}}
Expand All @@ -261,7 +282,7 @@ services: {{join $services ","}}

### replace

Alias for the strings.Replace function.
Alias for the [strings.Replace](https://golang.org/pkg/strings/#Replace) function.

```
{{$backend := getv "/services/backend/nginx"}}
Expand All @@ -270,7 +291,7 @@ backend = {{replace $backend "-" "_" -1}}

### lookupIP

Wrapper for net.LookupIP function. The wrapper also sorts (alphabeticaly) the IP addresses. This is crucial since in dynamic environments DNS servers typically shuffle the addresses linked to domain name. And that would cause unnecessary config reloads.
Wrapper for [net.LookupIP](https://golang.org/pkg/net/#LookupIP) function. The wrapper also sorts (alphabeticaly) the IP addresses. This is crucial since in dynamic environments DNS servers typically shuffle the addresses linked to domain name. And that would cause unnecessary config reloads.

```
{{range lookupIP "some.host.local"}}
Expand Down

0 comments on commit 27783ef

Please sign in to comment.