github.com/wynshop-open-source/gomplate@v3.5.0+incompatible/docs-src/content/functions/env.yml (about) 1 ns: env 2 preamble: | 3 [12-factor]: https://12factor.net 4 [Docker Secrets]: https://docs.docker.com/engine/swarm/secrets/#build-support-for-docker-secrets-into-your-images 5 funcs: 6 - name: env.Getenv 7 alias: getenv 8 description: | 9 Exposes the [os.Getenv](https://golang.org/pkg/os/#Getenv) function. 10 11 Retrieves the value of the environment variable named by the key. If the 12 variable is unset, but the same variable ending in `_FILE` is set, the contents 13 of the file will be returned. Otherwise the provided default (or an empty 14 string) is returned. 15 16 This is a more forgiving alternative to using `.Env`, since missing keys will 17 return an empty string, instead of panicking. 18 19 The `_FILE` fallback is especially useful for use with [12-factor][]-style 20 applications configurable only by environment variables, and especially in 21 conjunction with features like [Docker Secrets][]. 22 pipeline: false 23 arguments: 24 - name: var 25 required: true 26 description: the environment variable name 27 - name: default 28 required: false 29 description: the default 30 examples: 31 - | 32 $ gomplate -i 'Hello, {{env.Getenv "USER"}}' 33 Hello, hairyhenderson 34 $ gomplate -i 'Hey, {{getenv "FIRSTNAME" "you"}}!' 35 Hey, you! 36 - | 37 $ echo "safe" > /tmp/mysecret 38 $ export SECRET_FILE=/tmp/mysecret 39 $ gomplate -i 'Your secret is {{getenv "SECRET"}}' 40 Your secret is safe 41 - name: env.ExpandEnv 42 description: | 43 Exposes the [os.ExpandEnv](https://golang.org/pkg/os/#ExpandEnv) function. 44 45 Replaces `${var}` or `$var` in the input string according to the values of the 46 current environment variables. References to undefined variables are replaced by the empty string. 47 48 Like [`env.Getenv`](#env-getenv), the `_FILE` variant of a variable is used. 49 pipeline: false 50 arguments: 51 - name: input 52 required: true 53 description: the input 54 examples: 55 - | 56 $ gomplate -i '{{env.ExpandEnv "Hello $USER"}}' 57 Hello, hairyhenderson 58 $ gomplate -i 'Hey, {{env.ExpandEnv "Hey, ${FIRSTNAME}!"}}' 59 Hey, you! 60 - | 61 $ echo "safe" > /tmp/mysecret 62 $ export SECRET_FILE=/tmp/mysecret 63 $ gomplate -i '{{env.ExpandEnv "Your secret is $SECRET"}}' 64 Your secret is safe 65 - | 66 $ gomplate -i '{{env.ExpandEnv (file.Read "foo")}} 67 contents of file "foo"...