1
0
dwelling-radio/internal/http/handlers.go

54 lines
1.4 KiB
Go

package http
import (
"dwelling-radio/internal/radio"
"dwelling-radio/pkg/utils"
"dwelling-radio/web"
"net/http"
"os"
)
type Handlers struct {
songList *radio.SongList
listeners *radio.ListenerCounter
filelistPath string
}
func NewHandlers(filelistPath string, songList *radio.SongList, listeners *radio.ListenerCounter) *Handlers {
return &Handlers{
songList: songList,
filelistPath: filelistPath,
listeners: listeners}
}
func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) {
web.Index(utils.MainSite(r.Host), h.songList, h.listeners, r, w)
}
func (h *Handlers) Playlist(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Disposition", "attachment; filename=\"radio.arav.su.m3u\"")
fc, _ := web.AssetsGetFile("playlist.m3u")
w.Write(fc)
}
func (h *Handlers) Filelist(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Type", "text/html")
data, _ := os.ReadFile(h.filelistPath)
w.Write(data)
}
func RobotsTxt(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Disposition", "attachment; filename=\"robots.txt\"")
w.Write([]byte("User-agent: *\nDisallow: /assets/\nDisallow: /live/"))
}
func Favicon(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("img/favicon.svg")
w.Write(data)
}
func SitemapXML(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("sitemap.xml")
w.Write(data)
}