aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-02-17 07:54:30 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-02-17 07:54:30 +0100
commit45c9fdd5279e926c629c4e4fe3fd81b61c9c40dd (patch)
treebe3ddff8cd249a89779bac38c73a060d52f0e0b7
parenta57064fa2a6c8c5ca41713dbc9541f0cca4cfe27 (diff)
Parse template once
-rw-r--r--edit.go4
-rw-r--r--index.go4
-rw-r--r--view.go4
3 files changed, 9 insertions, 3 deletions
diff --git a/edit.go b/edit.go
index a425a1a..3a4ca37 100644
--- a/edit.go
+++ b/edit.go
@@ -9,8 +9,10 @@ func init() {
http.HandleFunc("/edit/", editHandler)
}
+var edittmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/edit"))
+
func editHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[len("/edit/"):]
p, _ := loadPage(title)
- p.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/edit")))
+ p.render(w, edittmpl)
}
diff --git a/index.go b/index.go
index 14f0ca9..10160ab 100644
--- a/index.go
+++ b/index.go
@@ -10,6 +10,8 @@ func init() {
http.HandleFunc("/index", indexHandler)
}
+var indextmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/index"))
+
func indexHandler(w http.ResponseWriter, r *http.Request) {
files, err := ioutil.ReadDir("data")
if err != nil {
@@ -23,5 +25,5 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
p.Pages = append(p.Pages, entry)
}
}
- p.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/index")))
+ p.render(w, indextmpl)
}
diff --git a/view.go b/view.go
index aae362e..3a1c47a 100644
--- a/view.go
+++ b/view.go
@@ -9,6 +9,8 @@ func init() {
http.HandleFunc("/view/", viewHandler)
}
+var viewtmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/view"))
+
func viewHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[len("/view/"):]
p, err := loadPage(title)
@@ -16,5 +18,5 @@ func viewHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/edit/"+title, http.StatusFound)
return
}
- p.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/view")))
+ p.render(w, viewtmpl)
}