summaryrefslogtreecommitdiff
path: root/templates.go
diff options
context:
space:
mode:
Diffstat (limited to 'templates.go')
-rw-r--r--templates.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/templates.go b/templates.go
index d18017f..6b4fe51 100644
--- a/templates.go
+++ b/templates.go
@@ -1,28 +1,22 @@
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)
+func setupTemplates() *template.Template {
+ t, err := template.ParseGlob(config.Http.Templates + "/*.html")
if err != nil {
- log.Print(err)
- http.Error(w, http.StatusText(404), 404)
- return
+ panic(err)
}
- 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)
+ return t
+}
+
+func ServeTemplate(w http.ResponseWriter, name string, data interface{}) {
+ err := templates.ExecuteTemplate(w, name, data)
if err != nil {
log.Print(err)
http.Error(w, http.StatusText(404), 404)