From 93f50458ec89cd6c5567444d9212e9bf0dc444a0 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 31 Mar 2022 18:34:33 +0400 Subject: [PATCH] Forgot about ReadFile() method of embed.FS. --- internal/handlers/handlers.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 97a2b11..57a9b23 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -7,10 +7,8 @@ import ( "dwelling-radio/pkg/utils" "embed" "encoding/json" - "fmt" "html/template" "io/fs" - "io/ioutil" "net/http" "time" @@ -56,18 +54,7 @@ func (h *RadioHandlers) AssetsFS() http.FileSystem { } func (h *RadioHandlers) Robots(w http.ResponseWriter, r *http.Request) { - f, err := h.AssetsFS().Open("robots.txt") - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - defer f.Close() - - fc, err := ioutil.ReadAll(f) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - } - + fc, _ := assetsDir.ReadFile("web/assets/robots.txt") w.Write(fc) } @@ -150,11 +137,8 @@ func (h *RadioHandlers) LastSong(w http.ResponseWriter, r *http.Request) { func (h *RadioHandlers) Playlist(w http.ResponseWriter, _ *http.Request) { w.Header().Add("Content-Disposition", "attachment; filename=\"radio.arav.top.m3u\"") - - pf, _ := assetsDir.Open("radio.arav.top.m3u") - defer pf.Close() - - fmt.Fprint(w, pf) + fc, _ := assetsDir.ReadFile("web/assets/radio.arav.top.m3u") + w.Write(fc) } func compileTemplates(lErr *logging.Logger) {