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