1
0

Let's actually remove unused handlers.

This commit is contained in:
Alexander Andreev 2023-10-08 22:50:36 +04:00
parent bbfdb8c956
commit 27affc5e73
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 0 additions and 65 deletions

View File

@ -68,19 +68,11 @@ func main() {
djh := ihttp.NewDJHandlers(lstnrs, plylst, songList, &mostListenedSong, *fallbackSong) 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 := r.Sub("/api")
s.Handler(http.MethodPost, "/listener/icecast", djh.ListenersUpdate) s.Handler(http.MethodPost, "/listener/icecast", djh.ListenersUpdate)
s.Handler(http.MethodGet, "/playlist", djh.PlaylistNext) s.Handler(http.MethodGet, "/playlist", djh.PlaylistNext)
s.Handler(http.MethodGet, "/status", djh.Status) 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) srv := ihttp.NewHttpServer(r)

View File

@ -60,31 +60,6 @@ func (dj *DJHandlers) ListenersUpdate(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) 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) { func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Type", "text/plain") w.Header().Add("Content-Type", "text/plain")
nxt := dj.playlist.Next() nxt := dj.playlist.Next()
@ -125,24 +100,6 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintln(w, nxt) 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) { 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 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) 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)
}
}