1
0

A /status endpoint was added that returns all data available. At this time cur song, listeners cur and peak, and a list of prev songs.

This commit is contained in:
Alexander Andreev 2023-10-01 22:07:04 +04:00
parent 96baa42fe0
commit aaf14e0c83
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 14 additions and 1 deletions

View File

@ -62,6 +62,8 @@ func main() {
r.Handler(http.MethodGet, "/song", djh.Song) r.Handler(http.MethodGet, "/song", djh.Song)
r.Handler(http.MethodGet, "/songs", djh.Songs) r.Handler(http.MethodGet, "/songs", djh.Songs)
r.Handler(http.MethodGet, "/status", djh.Status)
srv := ihttp.NewHttpServer(r) srv := ihttp.NewHttpServer(r)
if err := srv.Start(*listenAddress); err != nil { if err := srv.Start(*listenAddress); err != nil {

View File

@ -96,8 +96,19 @@ func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) {
} }
} }
func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) {
withList := r.URL.Query().Has("with-list")
if withList {
err := json.NewEncoder(w).Encode(&struct {
Current *radio.Song_ `json:"current_song,omitempty"`
Listeners *radio.ListenerCounter `json:"listeners"`
List []radio.Song_ `json:"last_songs,omitempty"`
}{
Current: songList.Current(),
Listeners: dj.listeners,
List: songList.List()})
if err != nil { if err != nil {
log.Println("DJHandlers.Song current:", err) log.Println("DJHandlers.Status-withList:", err)
} }
} }
} }