GithubHelp home page GithubHelp logo

gotemplate's Introduction

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.

gotemplate's People

Watchers

James Cloos avatar Jim Minter avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.