Skip to content

Instantly share code, notes, and snippets.

@dthtvwls
Last active June 8, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dthtvwls/cbce4c23660a3f0cf65d738718d46ced to your computer and use it in GitHub Desktop.
Save dthtvwls/cbce4c23660a3f0cf65d738718d46ced to your computer and use it in GitHub Desktop.
put a json structure on stdin, call `template-apply path/to/template`, receive executed template on stdout
package main
import (
"encoding/json"
"io/ioutil"
"os"
"text/template"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
var f interface{}
b, err := ioutil.ReadAll(os.Stdin)
check(err)
check(json.Unmarshal(b, &f))
check(template.Must(template.ParseFiles(os.Args[1])).Execute(os.Stdout, f))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment