github.com/wynshop-open-source/gomplate@v3.5.0+incompatible/docs/content/_index.md (about) 1 --- 2 title: gomplate 3 type: index 4 weight: 1 5 menu: 6 main: 7 name: About 8 --- 9 10 `gomplate` is a template renderer which supports a growing list of datasources, 11 such as: JSON (_including EJSON - encrypted JSON_), YAML, AWS EC2 metadata, [BoltDB](https://github.com/boltdb/bolt), 12 [Hashicorp Consul](https://www.consul.io/) and [Hashicorp Vault](https://www.vaultproject.io/) secrets. 13 14 Come chat with developers and community in the [#gomplate channel][] on [Gophers Slack][]! 15 16 _Please report any bugs found in the [issue tracker](https://github.com/hairyhenderson/gomplate/issues/)._ 17 18 ## Examples 19 20 Here are some hands-on examples of how `gomplate` works: 21 22 ```console 23 $ # at its most basic, gomplate can be used with environment variables... 24 $ echo 'Hello, {{ .Env.USER }}' | gomplate 25 Hello, hairyhenderson 26 27 $ # but that's kind of boring. gomplate has tons of functions to do useful stuff, too 28 $ gomplate -i 'the answer is: {{ mul 6 7 }}' 29 the answer is: 42 30 31 $ # and, since gomplate uses Go's templating syntax, you can do fun things like: 32 $ gomplate -i '{{ range seq 5 1 }}{{ . }} {{ if eq . 1 }}{{ "blastoff" | toUpper }}{{ end }}{{ end }}' 33 5 4 3 2 1 BLASTOFF 34 35 $ # the real fun comes when you use datasources! 36 $ cat ./config.yaml 37 foo: 38 bar: 39 baz: qux 40 $ gomplate -d config=./config.yaml -i 'the value we want is: {{ (datasource "config").foo.bar.baz }}' 41 the value we want is: qux 42 43 $ # datasources are defined by URLs, and gomplate is not limited to just file-based datasources: 44 $ gomplate -d ip=https://ipinfo.io -i 'country code: {{ (ds "ip").country }}' 45 country code: CA 46 47 $ # standard input can be used as a datasource too: 48 $ echo '{"cities":["London", "Johannesburg", "Windhoek"]}' | gomplate -d city=stdin:///in.json -i '{{ range (ds "city").cities }}{{.}}, {{end}}' 49 London, Johannesburg, Windhoek, 50 51 $ # and here's something a little more complicated: 52 $ export CITIES='city: [London, Johannesburg, Windhoek]' 53 $ cat in.tmpl 54 {{ range $i, $city := (ds "cities").city -}} 55 {{ add 1 $i }}: {{ include "weather" (print $city "?0") }} 56 {{ end }} 57 $ gomplate -d 'cities=env:///CITIES?type=application/yaml' -d 'weather=https://wttr.in/?0' -H 'weather=User-Agent: curl' -f in.tmpl 58 1: Weather report: London 59 60 \ / Partly cloudy 61 _ /"".-. 4-7 °C 62 \_( ). ↑ 20 km/h 63 /(___(__) 10 km 64 0.0 mm 65 66 2: Weather report: Johannesburg 67 68 \ / Partly cloudy 69 _ /"".-. 15 °C 70 \_( ). ↘ 0 km/h 71 /(___(__) 10 km 72 2.2 mm 73 74 3: Weather report: Windhoek 75 76 \ / Partly cloudy 77 _ /"".-. 20 °C 78 \_( ). ↑ 6 km/h 79 /(___(__) 20 km 80 0.0 mm 81 ``` 82 83 ## License 84 85 [The MIT License](http://opensource.org/licenses/MIT) 86 87 Copyright (c) 2016-{{< year >}} Dave Henderson 88 89 [datasources]: ../datasources 90 91 [Gophers Slack]: https://invite.slack.golangbridge.org 92 [#gomplate channel]: https://gophers.slack.com/messages/CGTR16RM2/