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:
parent
96baa42fe0
commit
aaf14e0c83
@ -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 {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user