In Status handler: added missing Content-Type; Added most listened song; Removed with-list query, just return everything; Added http.Error().
This commit is contained in:
parent
1b38c5d86c
commit
8322d2a7a8
@ -94,18 +94,21 @@ 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 {
|
||||
log.Println("DJHandlers.Status-withList:", err)
|
||||
}
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
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"`
|
||||
Mls *radio.MostListenedSong `json:"most_listened_song,omitempty"`
|
||||
}{
|
||||
Current: songList.Current(),
|
||||
Listeners: dj.listeners,
|
||||
List: songList.List(),
|
||||
Mls: radio.MostListened()})
|
||||
if err != nil {
|
||||
log.Println("DJHandlers.Status:", err)
|
||||
http.Error(w, "status parsing failed", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user