1
0

Added a robots.txt file and a handler for it.

This commit is contained in:
Alexander Andreev 2022-03-31 17:01:51 +04:00
parent 2b18204a6c
commit ee96af31ad
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
3 changed files with 21 additions and 0 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -0,0 +1,3 @@
User-agent: *
Disallow: /assets/
Disallow: /live/