From cccbc9f53799eb4232d22df8d48c00d55f2c029c Mon Sep 17 00:00:00 2001 From: jacobhartmann Date: Tue, 7 Nov 2017 12:52:02 +0100 Subject: [PATCH] added errorhandling --- websiteTemplate.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/websiteTemplate.go b/websiteTemplate.go index 3630ec0..2eaefb6 100644 --- a/websiteTemplate.go +++ b/websiteTemplate.go @@ -35,7 +35,18 @@ func main() { } +func errorHandler(w http.ResponseWriter, req *http.Request, status int) { + w.WriteHeader(status) + if status == http.StatusNotFound { + fmt.Fprint(w, "custom 404") + } +} + func blogHandler(w http.ResponseWriter, req *http.Request) { + if req.URL.Path != "/" { + errorHandler(w, req, http.StatusNotFound) + return + } posts = getNewestPosts(3) page := Page {name, sections, posts} renderTemplates(w, page)