From 3cea6bb8ba44a916219b5eb8d6607a3dc1ff0333 Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Sun, 26 Mar 2017 22:33:26 +0100 Subject: [PATCH] Add basic 404 page --- api/notfound.go | 14 ++++++++++++++ api/router.go | 1 + 2 files changed, 15 insertions(+) create mode 100644 api/notfound.go diff --git a/api/notfound.go b/api/notfound.go new file mode 100644 index 0000000..95fbe68 --- /dev/null +++ b/api/notfound.go @@ -0,0 +1,14 @@ +package api + +import ( + "net/http" + + "github.com/Sirupsen/logrus" +) + +type NotFound struct{} + +func (n NotFound) ServeHTTP(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(404) + logrus.Infof("%s %s not found.", r.Method, r.URL.String()) +} diff --git a/api/router.go b/api/router.go index e754256..9d0f6a3 100644 --- a/api/router.go +++ b/api/router.go @@ -12,5 +12,6 @@ func GetRouter(core core.Core, eventChannel chan *logrus.Entry) *mux.Router { r.HandleFunc("/autoscaler", AutoscalerList(core.Autoscalers)).Methods("GET") r.HandleFunc("/health", Health()).Methods("GET") r.HandleFunc("/events", Events(eventChannel)).Methods("GET") + r.NotFoundHandler = NotFound{} return r }