// Chapter 34 example: the same input through text/template and html/template. // This program has no server. It prints both results and stops. // Run with: go run exercises/34/06-text-template-danger.go package main import ( "fmt" htmltemplate "html/template" "os" texttemplate "text/template" ) const pageText = "
{{.}}
\n" const input = `` func main() { wrong := texttemplate.Must(texttemplate.New("wrong").Parse(pageText)) right := htmltemplate.Must(htmltemplate.New("right").Parse(pageText)) fmt.Println("text/template:") err := wrong.Execute(os.Stdout, input) if err != nil { fmt.Println("Error:", err) } fmt.Println("html/template:") err = right.Execute(os.Stdout, input) if err != nil { fmt.Println("Error:", err) } }