/song endpoint was broken into two, the second one is /songs that returns a list of prev played songs, and /song just a current one.
This commit is contained in:
parent
381da691a4
commit
96baa42fe0
@ -59,8 +59,8 @@ func main() {
|
|||||||
s = r.Sub("/playlist")
|
s = r.Sub("/playlist")
|
||||||
s.Handler(http.MethodGet, "/", djh.PlaylistNext)
|
s.Handler(http.MethodGet, "/", djh.PlaylistNext)
|
||||||
|
|
||||||
s = r.Sub("/song")
|
r.Handler(http.MethodGet, "/song", djh.Song)
|
||||||
s.Handler(http.MethodGet, "/", djh.Song)
|
r.Handler(http.MethodGet, "/songs", djh.Songs)
|
||||||
|
|
||||||
srv := ihttp.NewHttpServer(r)
|
srv := ihttp.NewHttpServer(r)
|
||||||
|
|
||||||
|
@ -79,15 +79,23 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dj *DJHandlers) Song(w http.ResponseWriter, r *http.Request) {
|
func (dj *DJHandlers) Song(w http.ResponseWriter, r *http.Request) {
|
||||||
isList := r.URL.Query().Has("list")
|
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
if isList {
|
err := json.NewEncoder(w).Encode(songList.Current())
|
||||||
err := json.NewEncoder(w).Encode(songList.List())
|
if err != nil {
|
||||||
if err != nil {
|
log.Println("DJHandlers.Song:", err)
|
||||||
log.Println("DJHandlers.Song list:", err)
|
http.Error(w, "cannot obtain current song", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
err := json.NewEncoder(w).Encode(songList.Current())
|
|
||||||
|
func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
err := json.NewEncoder(w).Encode(songList.List())
|
||||||
|
if err != nil {
|
||||||
|
log.Println("DJHandlers.Songs:", err)
|
||||||
|
http.Error(w, "cannot obtain list of last songs", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("DJHandlers.Song current:", err)
|
log.Println("DJHandlers.Song current:", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user