From e856a4b930016f30d1ab8bef31d737404c8153b4 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 22 May 2023 03:16:38 +0400 Subject: [PATCH] Endpoints reorganised a little. Handlers for assets are moved out of Handlers struct as a self-sustained funcs. --- cmd/dwelling-home/main.go | 10 +++++----- internal/http/handlers.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index 4c9ed32..a61e75a 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -72,7 +72,11 @@ func main() { srv.SetNotFoundHandler(http.NotFound) - srv.ServeStatic("/assets/*filepath", hand.AssetsFS()) + srv.ServeStatic("/assets/*filepath", http.AssetsFS()) + srv.GET("/robots.txt", http.RobotsTxt) + srv.GET("/rss.xml", hand.RSS) + srv.GET("/sitemap.xml", http.SitemapXml) + srv.GET("/", hand.Index) srv.GET("/stuff", hand.Stuff) srv.GET("/stuff/article/*filepath", hand.Article) @@ -82,10 +86,6 @@ func main() { srv.GET("/guestbook", hand.Guestbook) srv.GET("/guestbook/admin", hand.GuestbookAdmin) - srv.GET("/robots.txt", hand.Robots) - srv.GET("/rss.xml", hand.RSS) - srv.GET("/sitemap.xml", hand.Sitemap) - captchaApi := http.NewCaptchaApiHandlers(*captchaExpiry) srv.POST("/api/captcha/", captchaApi.New) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index b42d6a5..35ddc0b 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -38,10 +38,6 @@ func (h *Handlers) CloseDB() { h.guestbookDB.Close() } -func (h *Handlers) AssetsFS() http.FileSystem { - return web.Assets() -} - func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) { web.Index("", w) } @@ -160,12 +156,16 @@ func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) { web.RSS(r.URL.Scheme+"://"+r.Host, "Arav", posts, r, w) } -func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) { +func AssetsFS() http.FileSystem { + return web.Assets() +} + +func RobotsTxt(w http.ResponseWriter, r *http.Request) { data, _ := web.AssetsGetFile("robots.txt") w.Write(data) } -func (h *Handlers) Sitemap(w http.ResponseWriter, r *http.Request) { +func SitemapXml(w http.ResponseWriter, r *http.Request) { data, _ := web.AssetsGetFile("sitemap.xml") w.Write(data) }