added errorhandling

This commit is contained in:
Jacob 2017-11-07 12:52:02 +01:00
parent 80e925baf5
commit cccbc9f537

View File

@ -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) { func blogHandler(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
errorHandler(w, req, http.StatusNotFound)
return
}
posts = getNewestPosts(3) posts = getNewestPosts(3)
page := Page {name, sections, posts} page := Page {name, sections, posts}
renderTemplates(w, page) renderTemplates(w, page)