1
0

Added a MostListenedSong() handler.

This commit is contained in:
Alexander Andreev 2023-10-02 02:28:46 +04:00
parent 8322d2a7a8
commit f709ac4b02
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -110,5 +110,17 @@ func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) {
http.Error(w, "status parsing failed", http.StatusInternalServerError)
}
}
func (dj *DJHandlers) MostListenedSong(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
mls := radio.MostListened()
if mls == nil {
w.WriteHeader(http.StatusNotFound)
return
}
err := json.NewEncoder(w).Encode(mls)
if err != nil {
log.Println("DJHandlers.MostListenedSong:", err)
http.Error(w, "MostListenedSong parsing failed", http.StatusInternalServerError)
}
}