From 68e999777a758c1f4f4e1e13341d97799dd44f77 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Wed, 24 Oct 2012 21:08:34 +0200 Subject: [PATCH] Convert templates to global The templates will be parsed only on startup --- template.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/template.go b/template.go index b5080cd..71c2f43 100644 --- a/template.go +++ b/template.go @@ -23,20 +23,19 @@ func GetStatus(w http.ResponseWriter, r *http.Request) Status { return s } -func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) { - // TODO: when finish devel conver to global: - var templates = template.Must(template.ParseFiles(TEMPLATE_PATH+"header.html", - TEMPLATE_PATH+"footer.html", - TEMPLATE_PATH+"index.html", - TEMPLATE_PATH+"about.html", - TEMPLATE_PATH+"book.html", - TEMPLATE_PATH+"search.html", - TEMPLATE_PATH+"upload.html", - TEMPLATE_PATH+"new.html", - TEMPLATE_PATH+"read.html", - TEMPLATE_PATH+"edit.html", - )) +var templates = template.Must(template.ParseFiles(TEMPLATE_PATH+"header.html", + TEMPLATE_PATH+"footer.html", + TEMPLATE_PATH+"index.html", + TEMPLATE_PATH+"about.html", + TEMPLATE_PATH+"book.html", + TEMPLATE_PATH+"search.html", + TEMPLATE_PATH+"upload.html", + TEMPLATE_PATH+"new.html", + TEMPLATE_PATH+"read.html", + TEMPLATE_PATH+"edit.html", +)) +func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) { err := templates.ExecuteTemplate(w, tmpl+".html", data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError)