github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section4/gopherface/handlers/utility.go (about) 1 package handlers 2 3 import ( 4 "html/template" 5 "log" 6 "net/http" 7 ) 8 9 // Template rendering function 10 func RenderTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) { 11 t, err := template.ParseFiles(templateFile, WebAppRoot+"/templates/header.html", WebAppRoot+"/templates/footer.html") 12 if err != nil { 13 log.Printf("Error encountered while parsing the template: ", err) 14 } 15 t.Execute(w, templateData) 16 } 17 18 func RenderGatedTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) { 19 t, err := template.ParseFiles(templateFile, WebAppRoot+"/templates/gatedheader.html", WebAppRoot+"/templates/footer.html") 20 if err != nil { 21 log.Printf("Error encountered while parsing the template: ", err) 22 } 23 t.Execute(w, templateData) 24 } 25 26 /* 27 func RenderUnsafeTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) { 28 t, err := ttemplate.ParseFiles(templateFile) 29 if err != nil { 30 log.Printf("Error encountered while parsing the template: ", err) 31 } 32 w.Header().Set("X-XSS-Protection", "0") 33 t.Execute(w, templateData) 34 } 35 */