package main import ( "io/ioutil" "log" "net/http" "text/template" // FIXME switch to html/template for security reasons // and make a workaround for rendered Markdown insertion ) func ServeTemplate(w http.ResponseWriter, name string, path string, data interface{}) { templateFile, err := ioutil.ReadFile(path) if err != nil { log.Print(err) http.Error(w, http.StatusText(404), 404) return } tmpl, err := template.New(name).Parse(string(templateFile)) if err != nil { log.Print(err) http.Error(w, http.StatusText(404), 404) return } err = tmpl.Execute(w, data) if err != nil { log.Print(err) http.Error(w, http.StatusText(404), 404) return } }