Universal data-driven templates for generating textual output. Can be used as a single static binary (no dependencies) or as a golang library.
The renderer extends go-template and Sprig functions.
If you are interested in one of the use cases, take a look at this blog post about Kubernetes resources rendering. Also see Helm compatibility.
For binaries please visit the Releases Page.
The binaries are statically compiled and does not require any dependencies.
$ go get github.com/reefbarman/render
$ render --help
NAME:
render - Universal file renderer
USAGE:
render [global options] command [command options] [arguments...]
VERSION:
v0.0.4-cf8e3d3
AUTHOR:
reefbarman
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug, -d run in debug mode
--in value the input template file, stdin if empty
--out value the output file, stdout if empty
--config value optional configuration YAML file, can be used multiple times
--set value, --var value additional parameters in key=value format, can be used multiple times
--help, -h show help
--version, -v print the version
Notes:
--in
,--out
take only files (not directories) at the moment,--in
will consume any file as long as it can be parsedstdin
andstdout
can be used instead of--in
and--out
--config
accepts any YAML file, can be used multiple times, the values of the configs will be merged--set
,--var
are the same (one is used in Helm, the other in Terraform), we provide both for convenience, any values set here will override values form configuration files
Example usage of render
with stdin
, stdout
and --var
:
$ echo "something {{ .value }}" | render --var "value=new"
something new
Example usage of render
with --in
, --out
and --config
:
$ echo "something {{ .value }}" > test.txt.tmpl
$ echo "value: new" > test.config.yaml
$ ./render --in test.txt.tmpl --out test.txt --config test.config.yaml
$ cat test.txt
something new
Also see a more advanced template example.
package example
import (
"github.com/reefbarman/render/renderer"
"github.com/reefbarman/render/renderer/configuration"
)
func CustomRender(template string) (string, error) {
config := configuration.Configuration{}
r := renderer.New(config, renderer.MissingKeyErrorOption)
return r.Render("nameless", template)
}
See also RenderWith
function that takes a custom functions map.
Also see tests for more usage examples.
All syntax and functions:
render
- calls therender
from inside of the template, making the renderer recursivereadFile
- reads a file from a path, relative paths are translated to absolute paths, based onroot
functionroot
- the root path, used for relative to absolute path translation in any file based operations; by defaultPWD
is usedtoYaml
- provides a configuration data structure fragment as a YAML formatgzip
,ungzip
- usegzip
compression and extraction inside the templates, for best results use withb64enc
andb64dec
See also example template and a more detailed documentation.
As of now, there is a limited Helm 2 Chart compatibility, simple Charts will render just fine.
There is no plan to implement full compatibility with Helm, because of unnecessary complexity that would bring.
encrypt
,decrypt
- cloud KMS (AWS, Amazon, Google) based encryption for any data
- directories as
--in
and--out
arguments, currently only files are supported
We provide cross-compiled binaries for most platforms, but is currently used mainly with linux/amd64
.
Feel free to file issues or pull requests.
mkdir $GOPATH/src/github.com/reefbarman/
git clone
go get -u github.com/golang/dep/cmd/dep
export PATH=$PATH:$GOPATH/bin
cd $GOPATH/src/github.com/reefbarman/render
make all
We believe in obvious names. It renders. It's a verb. It's render
.