diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index c3f129f..9617ad4 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -60,10 +60,10 @@ func main() { } r.ServeStatic("/assets/*filepath", web.Assets()) - r.Handler(http.MethodGet, "/favicon.ico", dwhttp.FaviconIco) - r.Handler(http.MethodGet, "/robots.txt", dwhttp.RobotsTxt) + r.Handler(http.MethodGet, "/favicon.ico", dwhttp.ServeAsset("img/favicon.ico")) + r.Handler(http.MethodGet, "/robots.txt", dwhttp.ServeAsset("robots.txt")) r.Handler(http.MethodGet, "/rss.xml", hand.RSS) - r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.SitemapXml) + r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.ServeAsset("sitemap.xml")) r.Handler(http.MethodGet, "/", hand.Index) r.Handler(http.MethodGet, "/privacy", hand.Privacy) diff --git a/internal/http/web_handlers.go b/internal/http/web_handlers.go index 13bd093..58b0b8b 100644 --- a/internal/http/web_handlers.go +++ b/internal/http/web_handlers.go @@ -168,29 +168,20 @@ func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) { if err != nil { return } - var scheme string - if r.Header.Get("Scheme") != "" { - scheme = r.Header.Get("Scheme") - } else { + + scheme := r.Header.Get("Scheme") + if scheme == "" { scheme = "http" } web.RSS(scheme+"://"+r.Host, h.owner, posts, r, w) } -func FaviconIco(w http.ResponseWriter, r *http.Request) { - data, _ := web.AssetsGetFile("img/favicon.ico") - w.Write(data) -} - -func RobotsTxt(w http.ResponseWriter, r *http.Request) { - data, _ := web.AssetsGetFile("robots.txt") - w.Write(data) -} - -func SitemapXml(w http.ResponseWriter, r *http.Request) { - data, _ := web.AssetsGetFile("sitemap.xml") - w.Write(data) +func ServeAsset(path string) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + data, _ := web.AssetsGetFile(path) + w.Write(data) + } } func Error(w http.ResponseWriter, code int, reason, message, referer string) {