While I want thread safety I also want a not set current song to not appear in a status JSON object.
This commit is contained in:
parent
07b0199193
commit
020676f113
@ -92,13 +92,18 @@ func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) {
|
func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
var curSong *radio.Song = nil
|
||||||
|
if dj.songList.Current() != nil {
|
||||||
|
curSong = &radio.Song{}
|
||||||
|
*curSong = *dj.songList.Current()
|
||||||
|
}
|
||||||
err := json.NewEncoder(w).Encode(&struct {
|
err := json.NewEncoder(w).Encode(&struct {
|
||||||
Current radio.Song `json:"current_song,omitempty"`
|
Current *radio.Song `json:"current_song,omitempty"`
|
||||||
Listeners *radio.ListenerCounter `json:"listeners"`
|
Listeners *radio.ListenerCounter `json:"listeners"`
|
||||||
List []radio.Song `json:"last_songs,omitempty"`
|
List []radio.Song `json:"last_songs,omitempty"`
|
||||||
Mls *radio.MostListenedSong `json:"most_listened_song,omitempty"`
|
Mls *radio.MostListenedSong `json:"most_listened_song,omitempty"`
|
||||||
}{
|
}{
|
||||||
Current: dj.songList.Current(),
|
Current: curSong,
|
||||||
Listeners: dj.listeners,
|
Listeners: dj.listeners,
|
||||||
List: dj.songList.List(),
|
List: dj.songList.List(),
|
||||||
Mls: radio.MostListened()})
|
Mls: radio.MostListened()})
|
||||||
|
Loading…
Reference in New Issue
Block a user