Last active
June 8, 2018 17:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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