tpls

Extendable, Fast Template Engine for Go
git clone git://git.lair.cx/tpls
Log | Files | Refs | README | LICENSE

main.go (478B)


      1 package main
      2 
      3 import (
      4 	"log"
      5 	"net/http"
      6 
      7 	"go.lair.cx/tpls"
      8 	"go.lair.cx/tpls/examples/basic/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.MainPage{
     18 		Name: "World",
     19 		Cond: 1,
     20 	})
     21 	w.Header().Set("Content-Type", "text/html;charset=utf-8")
     22 	w.WriteHeader(http.StatusOK)
     23 	_, _ = w.Write(tplw.Bytes())
     24 }