From 27affc5e7397683817636939cef9a25d3aeaf550 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 8 Oct 2023 22:50:36 +0400 Subject: [PATCH] Let's actually remove unused handlers. --- cmd/dwelling-radio/main.go | 8 ----- internal/http/dj_handlers.go | 57 ------------------------------------ 2 files changed, 65 deletions(-) diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index cdcf37a..2e2d3cc 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -68,19 +68,11 @@ func main() { djh := ihttp.NewDJHandlers(lstnrs, plylst, songList, &mostListenedSong, *fallbackSong) - // s := r.Sub("/api/listener") - // s.Handler(http.MethodGet, "/", djh.ListenersGet) - // s.Handler(http.MethodPost, "/", djh.ListenersInc) - // s.Handler(http.MethodDelete, "/", djh.ListenersDec) - s := r.Sub("/api") s.Handler(http.MethodPost, "/listener/icecast", djh.ListenersUpdate) s.Handler(http.MethodGet, "/playlist", djh.PlaylistNext) s.Handler(http.MethodGet, "/status", djh.Status) - // s.Handler(http.MethodGet, "/song", djh.Song) - // s.Handler(http.MethodGet, "/songs", djh.Songs) - // s.Handler(http.MethodGet, "/mostlistenedsong", djh.MostListenedSong) srv := ihttp.NewHttpServer(r) diff --git a/internal/http/dj_handlers.go b/internal/http/dj_handlers.go index fc76826..4918efe 100644 --- a/internal/http/dj_handlers.go +++ b/internal/http/dj_handlers.go @@ -60,31 +60,6 @@ func (dj *DJHandlers) ListenersUpdate(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -func (dj *DJHandlers) ListenersGet(w http.ResponseWriter, _ *http.Request) { - w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(dj.listeners) -} - -func (dj *DJHandlers) ListenersInc(w http.ResponseWriter, _ *http.Request) { - l := dj.listeners.Inc() - go dj.songList.UpdateCurrentMaxListeners(l) - w.WriteHeader(http.StatusCreated) - w.Header().Add("Content-Type", "text/plain") - fmt.Fprint(w, l) -} - -func (dj *DJHandlers) ListenersDec(w http.ResponseWriter, _ *http.Request) { - l, err := dj.listeners.Dec() - if err != nil { - log.Print(err) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - w.WriteHeader(http.StatusOK) - w.Header().Add("Content-Type", "text/plain") - fmt.Fprint(w, l) -} - func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) { w.Header().Add("Content-Type", "text/plain") nxt := dj.playlist.Next() @@ -125,24 +100,6 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) { fmt.Fprintln(w, nxt) } -func (dj *DJHandlers) Song(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(dj.songList.Current()) - if err != nil { - log.Println("DJHandlers.Song:", err) - http.Error(w, "cannot obtain current song", http.StatusInternalServerError) - } -} - -func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(dj.songList.List()) - if err != nil { - log.Println("DJHandlers.Songs:", err) - http.Error(w, "cannot obtain list of last songs", http.StatusInternalServerError) - } -} - func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "application/json") var curSong *radio.Song = nil @@ -165,17 +122,3 @@ func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) { http.Error(w, "status parsing failed", http.StatusInternalServerError) } } - -func (dj *DJHandlers) MostListenedSong(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Content-Type", "application/json") - mls := dj.mostLSong.Get() - if mls == nil { - w.WriteHeader(http.StatusNotFound) - return - } - err := json.NewEncoder(w).Encode(mls) - if err != nil { - log.Println("DJHandlers.MostListenedSong:", err) - http.Error(w, "MostListenedSong parsing failed", http.StatusInternalServerError) - } -}