main.go (467B)
1 package main 2 3 import ( 4 "log" 5 "net/http" 6 7 "go.lair.cx/tpls" 8 "go.lair.cx/tpls/examples/plaintext/templates" 9 ) 10 11 func main() { 12 log.Fatalln(http.ListenAndServe(":8080", http.HandlerFunc(handler))) 13 } 14 15 func handler(w http.ResponseWriter, r *http.Request) { 16 tplw := tpls.NewWriter(nil) 17 templates.Render(tplw, &templates.Body{ 18 Name: "World", 19 }) 20 w.Header().Set("Content-Type", "text/html;charset=utf-8") 21 w.WriteHeader(http.StatusOK) 22 _, _ = w.Write(tplw.Bytes()) 23 }