From 55ed1589484faec00a3cc9ca72fcd680ed0eff94 Mon Sep 17 00:00:00 2001 From: Herman Schaaf Date: Mon, 30 May 2016 21:23:58 +0800 Subject: [PATCH] Custom 404 page Closes #101 --- handlers/error.go | 14 +++++++ handlers/home.go | 2 +- templates/404.html | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 handlers/error.go create mode 100644 templates/404.html diff --git a/handlers/error.go b/handlers/error.go new file mode 100644 index 0000000..14956a1 --- /dev/null +++ b/handlers/error.go @@ -0,0 +1,14 @@ +package handlers + +import ( + "html/template" + "net/http" +) + +func errorHandler(w http.ResponseWriter, r *http.Request, status int) { + w.WriteHeader(status) + if status == http.StatusNotFound { + t := template.Must(template.New("404.html").ParseFiles("templates/404.html")) + t.Execute(w, nil) + } +} diff --git a/handlers/home.go b/handlers/home.go index 786f934..c38f33d 100644 --- a/handlers/home.go +++ b/handlers/home.go @@ -57,5 +57,5 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) { return } - http.NotFound(w, r) + errorHandler(w, r, http.StatusNotFound) } diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..271eabe --- /dev/null +++ b/templates/404.html @@ -0,0 +1,99 @@ + + + + + + + Go Report Card | Go project code quality report cards + + + + + +
+
+ + + + + + + + + + + +
+ + High Scores + + + GitHub + + + About + +
+
+
+
+
+
+
+ +
+
+
+

Page not found!

+

It seems like the page you are looking for is no longer here. Check the URL for typos, or click below to return to the homepage. If you think this is a mistake, please open an issue on Github.

+

Back to grading Go repos

+
+
+
+ + + +