Cache templates

This commit is contained in:
Eliot Whalan 2016-06-24 11:16:58 +10:00
parent e1f18e7ef0
commit a3d5f547d3
1 changed files with 5 additions and 5 deletions

10
main.go
View File

@ -226,6 +226,9 @@ func getPaste(paste string, lang string) string {
} }
var templates = template.Must(template.ParseFiles("assets/paste.html"))
var syntax, _ = ioutil.ReadFile("assets/syntax.html")
func pasteHandler(w http.ResponseWriter, r *http.Request) { func pasteHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
paste := vars["pasteId"] paste := vars["pasteId"]
@ -239,16 +242,13 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
Raw: link, Raw: link,
Home: ADDRESS, Home: ADDRESS,
} }
t, err := template.ParseFiles("assets/paste.html") err := templates.ExecuteTemplate(w, "assets/paste.html", p)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
t.Execute(w, p)
} else { } else {
dat, err := ioutil.ReadFile("assets/syntax.html") fmt.Fprintf(w, string(syntax), paste, paste, s, ADDRESS, link)
check(err)
fmt.Fprintf(w, string(dat), paste, paste, s, ADDRESS, link)
} }
} }