Skip to content

Instantly share code, notes, and snippets.

@suzuken
Created August 26, 2015 02:51
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 suzuken/f6e8d1c21fa4951f93d5 to your computer and use it in GitHub Desktop.
Save suzuken/f6e8d1c21fa4951f93d5 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"os"
"text/template"
)
func main() {
flag.Parse()
fmt.Println(flag.Arg(0))
t, err := template.New("").Parse(flag.Arg(0))
if err != nil {
fmt.Fprintf(os.Stderr, "build template failed: %s\n", err)
os.Exit(1)
}
if err := t.Execute(os.Stdout, "test"); err != nil {
fmt.Fprintf(os.Stderr, "execution failed: %s\n", err)
os.Exit(1)
}
// -> % go run /tmp/t.go 'input: {{printf "%q" .}}'
// input: {{printf "%q" .}}
// input: "test"%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment