github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume2/section5/gopherfacedb/handlers/utility.go (about) 1 package handlers 2 3 import ( 4 "html/template" 5 "log" 6 "net/http" 7 ttemplate "text/template" 8 ) 9 10 // Template rendering function 11 func RenderTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) { 12 t, err := template.ParseFiles(templateFile) 13 if err != nil { 14 log.Printf("Error encountered while parsing the template: ", err) 15 } 16 t.Execute(w, templateData) 17 } 18 19 func RenderUnsafeTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) { 20 t, err := ttemplate.ParseFiles(templateFile) 21 if err != nil { 22 log.Printf("Error encountered while parsing the template: ", err) 23 } 24 w.Header().Set("X-XSS-Protection", "0") 25 t.Execute(w, templateData) 26 }