From aec332f746615c724957d8f0944c7ed24404a3a7 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 5 Feb 2023 05:25:20 +0400 Subject: [PATCH] Added error 404 handler. --- cmd/dwelling-home/main.go | 2 ++ internal/http/handlers.go | 4 ++++ web/web.go | 2 ++ 3 files changed, 8 insertions(+) diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index 2343d00..466b3bd 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -51,6 +51,8 @@ func main() { hand := http.NewHandlers(*captchaExpiry, *databasesPath, *guestbookOwner, *guestbookPageSize) srv := http.NewHttpServer() + srv.SetNotFoundHandler(hand.NotFound) + srv.ServeStatic("/assets/*filepath", hand.AssetsFS()) srv.GET("/", hand.Index) srv.GET("/stuff", hand.Stuff) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 429b192..cfff945 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -81,3 +81,7 @@ func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) { data, _ := web.AssetsGetFile("robots.txt") w.Write(data) } + +func (h *Handlers) NotFound(w http.ResponseWriter, r *http.Request) { + web.NotFound("Not Found", w) +} diff --git a/web/web.go b/web/web.go index 811512c..8cad82e 100644 --- a/web/web.go +++ b/web/web.go @@ -17,6 +17,8 @@ import ( //go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer article.pug +//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -stdbuf -stdlib -writer error404.pug + //go:embed assets var assetsDir embed.FS