diff --git a/main.go b/main.go index edf085b..e07a58c 100644 --- a/main.go +++ b/main.go @@ -12,28 +12,22 @@ func pageHandler(w http.ResponseWriter, r *http.Request) { if path == "/" { path = "/home" } - - tmpl, err := template.Must(template.ParseGlob("templates/*.html")).Clone() - if err != nil { - http.NotFound(w, r) - return - } - - _, err = tmpl.ParseFiles(filepath.Join("pages", path+".html")) + t, err := template.Must(template.ParseGlob("templates/*.html")).Clone() if err != nil { http.NotFound(w, r) return } - - err = tmpl.ExecuteTemplate(w, "layout", nil) - if err != nil { + if _, err := t.ParseFiles(filepath.Join("pages", path+".html")); err != nil { + http.NotFound(w, r) + return + } + if err := t.ExecuteTemplate(w, "layout", nil); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } func main() { http.HandleFunc("/", pageHandler) - log.Println("Server running at http://localhost:14888") log.Fatal(http.ListenAndServe(":14888", nil)) }