Skip to content

jim-minter/gotemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotemplate

Proof of concept portable/container-friendly command-line tool to wrap Golang's text/template capabilities.

Author

  • Jim Minter (jminter at redhat.com)

Installation

go get github.com/jim-minter/gotemplate
$GOPATH/bin/gotemplate

(alternatively a pre-compiled binary for Linux x86_64 is checked in - caveat emptor)

Documentation

Golang's text/template capabilities are powerful and are fully documented at https://golang.org/pkg/text/template/.

Usage: gotemplate [-j JSONFILE | -y YAMLFILE] [-missingkey default|invalid|zero|error] TEMPLATE...

  -j JSONFILE
    	read data from JSONFILE
  -missingkey missingkey
    	missingkey option, see https://golang.org/pkg/text/template/#Template.Option (default "default")
  -y YAMLFILE
    	read data from YAMLFILE

Examples

# Populate a freeform output file based on environment variables
$GOPATH/bin/gotemplate $GOPATH/src/github.com/jim-minter/gotemplate/examples/example1.tmpl

# Same, but fail on any required but missing environment variables
$GOPATH/bin/gotemplate -missingkey error $GOPATH/src/github.com/jim-minter/gotemplate/examples/example1.tmpl
echo $?

# Populate an XML output file based on JSON input
$GOPATH/bin/gotemplate -j $GOPATH/src/github.com/jim-minter/gotemplate/examples/example2.json $GOPATH/src/github.com/jim-minter/gotemplate/examples/example2.tmpl

# Populate an XML output file based on YAML input
$GOPATH/bin/gotemplate -y $GOPATH/src/github.com/jim-minter/gotemplate/examples/example2.yaml $GOPATH/src/github.com/jim-minter/gotemplate/examples/example2.tmpl

# Call out to a Golang API function from a template
$GOPATH/bin/gotemplate $GOPATH/src/github.com/jim-minter/gotemplate/examples/example3.tmpl

Available functions

In addition to the default functions available using text/template, the following are also available:

Making additional functions available is quite straightforward: e-mail or send a pull request if you require others.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages