1
0

Forgot about ReadFile() method of embed.FS.

This commit is contained in:
Alexander Andreev 2022-03-31 18:34:33 +04:00
parent 981bbd8968
commit 93f50458ec
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -7,10 +7,8 @@ import (
"dwelling-radio/pkg/utils" "dwelling-radio/pkg/utils"
"embed" "embed"
"encoding/json" "encoding/json"
"fmt"
"html/template" "html/template"
"io/fs" "io/fs"
"io/ioutil"
"net/http" "net/http"
"time" "time"
@ -56,18 +54,7 @@ func (h *RadioHandlers) AssetsFS() http.FileSystem {
} }
func (h *RadioHandlers) Robots(w http.ResponseWriter, r *http.Request) { func (h *RadioHandlers) Robots(w http.ResponseWriter, r *http.Request) {
f, err := h.AssetsFS().Open("robots.txt") fc, _ := assetsDir.ReadFile("web/assets/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)
}
w.Write(fc) 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) { func (h *RadioHandlers) Playlist(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Disposition", "attachment; filename=\"radio.arav.top.m3u\"") w.Header().Add("Content-Disposition", "attachment; filename=\"radio.arav.top.m3u\"")
fc, _ := assetsDir.ReadFile("web/assets/radio.arav.top.m3u")
pf, _ := assetsDir.Open("radio.arav.top.m3u") w.Write(fc)
defer pf.Close()
fmt.Fprint(w, pf)
} }
func compileTemplates(lErr *logging.Logger) { func compileTemplates(lErr *logging.Logger) {