github.com/hairyhenderson/gomplate/v3@v3.11.7/README.md (about) 1 <img src="docs/static/images/gomplate.png" width="512px" alt="gomplate logo"/> 2 3 _Read the docs at [docs.gomplate.ca][docs-url], chat with developers and community in the [#gomplate channel][] on [Gophers Slack][]_ 4 5 [![Build Status][circleci-image]][circleci-url] 6 [![Build][gh-actions-image]][gh-actions-url] 7 [![Go Report Card][reportcard-image]][reportcard-url] 8 [![Codebeat Status][codebeat-image]][codebeat-url] 9 [![Coverage][gocover-image]][gocover-url] 10 [![Total Downloads][gh-downloads-image]][gh-downloads-url] 11 [![CII Best Practices][cii-bp-image]][cii-bp-url] 12 13 [![hairyhenderson/gomplate on DockerHub][dockerhub-image]][dockerhub-url] 14 [![DockerHub Stars][dockerhub-stars-image]][dockerhub-url] 15 [![DockerHub Pulls][dockerhub-pulls-image]][dockerhub-url] 16 [![DockerHub Image Layers][microbadger-layers-image]][microbadger-url] 17 [![DockerHub Latest Version ][microbadger-version-image]][microbadger-url] 18 [![DockerHub Latest Commit][microbadger-commit-image]][microbadger-url] 19 20 [![Chocolatey](https://img.shields.io/chocolatey/v/gomplate.svg)](https://chocolatey.org/packages/gomplate) 21 [![Chocolatey](https://img.shields.io/chocolatey/dt/gomplate.svg)](https://chocolatey.org/packages/gomplate) 22 23 [![Install Docs][install-docs-image]][install-docs-url] 24 [![Slack][slack-image]][slack-url] 25 [![Discussions][discussions-image]][discussions-url] 26 27 `gomplate` is a template renderer which supports a growing list of datasources, 28 such as: JSON (_including EJSON - encrypted JSON_), YAML, AWS EC2 metadata, [BoltDB](https://pkg.go.dev/go.etcd.io/bbolt), 29 [Hashicorp Consul](https://www.consul.io/) and [Hashicorp Vault](https://www.vaultproject.io/) secrets. 30 31 Come chat with developers and community in the [#gomplate channel][] on [Gophers Slack][] and on [GitHub Discussions][discussions-url]! 32 33 Here are some hands-on examples of how `gomplate` works: 34 35 ```console 36 $ # at its most basic, gomplate can be used with environment variables... 37 $ echo 'Hello, {{ .Env.USER }}' | gomplate 38 Hello, hairyhenderson 39 40 $ # but that's kind of boring. gomplate has tons of functions to do useful stuff, too 41 $ gomplate -i 'the answer is: {{ mul 6 7 }}' 42 the answer is: 42 43 44 $ # and, since gomplate uses Go's templating syntax, you can do fun things like: 45 $ gomplate -i '{{ range seq 5 1 }}{{ . }} {{ if eq . 1 }}{{ "blastoff" | toUpper }}{{ end }}{{ end }}' 46 5 4 3 2 1 BLASTOFF 47 48 $ # the real fun comes when you use datasources! 49 $ cat ./config.yaml 50 foo: 51 bar: 52 baz: qux 53 $ gomplate -d config=./config.yaml -i 'the value we want is: {{ (datasource "config").foo.bar.baz }}' 54 the value we want is: qux 55 56 $ # datasources are defined by URLs, and gomplate is not limited to just file-based datasources: 57 $ gomplate -d ip=https://ipinfo.io -i 'country code: {{ (ds "ip").country }}' 58 country code: CA 59 60 $ # standard input can be used as a datasource too: 61 $ echo '{"cities":["London", "Johannesburg", "Windhoek"]}' | gomplate -d city=stdin:///in.json -i '{{ range (ds "city").cities }}{{.}}, {{end}}' 62 London, Johannesburg, Windhoek, 63 64 $ # and here's something a little more complicated: 65 $ export CITIES='city: [London, Johannesburg, Windhoek]' 66 $ cat in.tmpl 67 {{ range $i, $city := (ds "cities").city -}} 68 {{ add 1 $i }}: {{ include "weather" (print $city "?0") }} 69 {{ end }} 70 $ gomplate -d 'cities=env:///CITIES?type=application/yaml' -d 'weather=https://wttr.in/?0' -H 'weather=User-Agent: curl' -f in.tmpl 71 1: Weather report: London 72 73 \ / Partly cloudy 74 _ /"".-. 4-7 °C 75 \_( ). ↑ 20 km/h 76 /(___(__) 10 km 77 0.0 mm 78 79 2: Weather report: Johannesburg 80 81 \ / Partly cloudy 82 _ /"".-. 15 °C 83 \_( ). ↘ 0 km/h 84 /(___(__) 10 km 85 2.2 mm 86 87 3: Weather report: Windhoek 88 89 \ / Partly cloudy 90 _ /"".-. 20 °C 91 \_( ). ↑ 6 km/h 92 /(___(__) 20 km 93 0.0 mm 94 ``` 95 96 Read the documentation at [docs.gomplate.ca][docs-url], and join the discussion 97 in [GitHub Discussions][discussions-url]! 98 99 _Please report any bugs found in the [issue tracker](https://github.com/hairyhenderson/gomplate/issues/)._ 100 101 ## License 102 103 [The MIT License](http://opensource.org/licenses/MIT) 104 105 Copyright (c) 2016-2021 Dave Henderson 106 107 [circleci-image]: https://img.shields.io/circleci/project/github/hairyhenderson/gomplate/master.svg?logo=circleci 108 [circleci-url]: https://circleci.com/gh/hairyhenderson/gomplate/tree/master 109 110 [gh-actions-image]: https://github.com/hairyhenderson/gomplate/workflows/Build/badge.svg?branch=master 111 [gh-actions-url]: https://github.com/hairyhenderson/gomplate/actions?workflow=Build&branch=master 112 113 [reportcard-image]: https://goreportcard.com/badge/github.com/hairyhenderson/gomplate 114 [reportcard-url]: https://goreportcard.com/report/github.com/hairyhenderson/gomplate 115 [codebeat-image]: https://codebeat.co/badges/39ed2148-4b86-4d1e-8526-25f60e159ba1 116 [codebeat-url]: https://codebeat.co/projects/github-com-hairyhenderson-gomplate 117 [gocover-image]: https://gocover.io/_badge/github.com/hairyhenderson/gomplate 118 [gocover-url]: https://gocover.io/github.com/hairyhenderson/gomplate 119 [gh-downloads-image]: https://img.shields.io/github/downloads/hairyhenderson/gomplate/total.svg 120 [gh-downloads-url]: https://github.com/hairyhenderson/gomplate/releases 121 122 [cii-bp-image]: https://bestpractices.coreinfrastructure.org/projects/337/badge 123 [cii-bp-url]: https://bestpractices.coreinfrastructure.org/projects/337 124 125 [dockerhub-image]: https://img.shields.io/badge/docker-ready-blue.svg 126 [dockerhub-url]: https://hub.docker.com/r/hairyhenderson/gomplate 127 [dockerhub-stars-image]: https://img.shields.io/docker/stars/hairyhenderson/gomplate.svg 128 [dockerhub-pulls-image]: https://img.shields.io/docker/pulls/hairyhenderson/gomplate.svg 129 130 [microbadger-version-image]: https://images.microbadger.com/badges/version/hairyhenderson/gomplate.svg 131 [microbadger-layers-image]: https://images.microbadger.com/badges/image/hairyhenderson/gomplate.svg 132 [microbadger-commit-image]: https://images.microbadger.com/badges/commit/hairyhenderson/gomplate.svg 133 [microbadger-url]: https://microbadger.com/image/hairyhenderson/gomplate 134 135 [docs-url]: https://docs.gomplate.ca 136 [install-docs-image]: https://img.shields.io/badge/install-docs-blue.svg 137 [install-docs-url]: https://docs.gomplate.ca/installing 138 139 [Gophers Slack]: https://invite.slack.golangbridge.org 140 [#gomplate channel]: https://gophers.slack.com/messages/CGTR16RM2/ 141 142 [slack-image]: https://img.shields.io/badge/slack-gophers/%23gomplate-00ADD8.svg?logo=slack 143 [slack-url]: https://gophers.slack.com/messages/CGTR16RM2/ 144 145 [discussions-image]: https://img.shields.io/badge/discussions-gomplate-blue.svg?logo=github 146 [discussions-url]: https://github.com/hairyhenderson/gomplate/discussions 147 148 [![Analytics](https://ga-beacon.appspot.com/UA-82637990-1/gomplate/README.md?pixel)](https://github.com/igrigorik/ga-beacon)