Added a robots.txt file and a handler for it.
This commit is contained in:
parent
2b18204a6c
commit
ee96af31ad
@ -57,6 +57,7 @@ func main() {
|
|||||||
|
|
||||||
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())
|
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())
|
||||||
srv.GET("/", hand.Index)
|
srv.GET("/", hand.Index)
|
||||||
|
srv.GET("/robots.txt", hand.Robots)
|
||||||
srv.GET("/stats", hand.Stats)
|
srv.GET("/stats", hand.Stats)
|
||||||
srv.GET("/lastsong", hand.LastSong)
|
srv.GET("/lastsong", hand.LastSong)
|
||||||
srv.GET("/playlist", hand.Playlist)
|
srv.GET("/playlist", hand.Playlist)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -54,6 +55,22 @@ func (h *RadioHandlers) AssetsFS() http.FileSystem {
|
|||||||
return http.FS(f)
|
return http.FS(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(fc)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) {
|
func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) {
|
||||||
status, err := radio.IcecastGetStatus(h.conf.Icecast.URL)
|
status, err := radio.IcecastGetStatus(h.conf.Icecast.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
3
internal/handlers/web/assets/robots.txt
Normal file
3
internal/handlers/web/assets/robots.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /assets/
|
||||||
|
Disallow: /live/
|
Loading…
Reference in New Issue
Block a user