From 978b4c6454ea67eb00dd98fa5af1fd867eadc243 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 14 Sep 2023 17:59:14 +0400 Subject: [PATCH] Removed unused error returning (error is always nil). --- internal/http/handlers.go | 12 +++--------- internal/radio/icecast.go | 12 ++++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index f821c6e..a942939 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -32,10 +32,8 @@ func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) { log.Println("failed to get Icecast status:", err) } - songs, err := radio.IcecastLastSongs(h.icecastPlaylistPath) - if err != nil { - log.Println("cannot retrieve last songs:", err) - } else { + songs := radio.IcecastLastSongs(h.icecastPlaylistPath) + if songs != nil { for i := 0; i < len(songs); i++ { if tim, err := time.Parse(radio.SongTimeFormat, songs[i].Time); err == nil { songs[i].Time = utils.ToClientTimezone(tim, r).Format("15:04") @@ -59,11 +57,7 @@ func (h *Handlers) Status(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) LastSong(w http.ResponseWriter, r *http.Request) { - song, err := radio.IcecastLastSong(h.icecastPlaylistPath) - if err != nil { - log.Println("cannot retrieve last songs:", err) - } - + song := radio.IcecastLastSong(h.icecastPlaylistPath) if song == nil { w.WriteHeader(http.StatusNotFound) return diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 208e302..05aabe8 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -76,25 +76,25 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) { }, nil } -func IcecastLastSongs(playlistPath string) ([]Song, error) { +func IcecastLastSongs(playlistPath string) []Song { lastPlayedCacheMutex.Lock() defer lastPlayedCacheMutex.Unlock() if lpcLen := len(lastPlayedCache); lpcLen > 0 { ret := make([]Song, 0, lpcLen) ret = append(ret, lastPlayedCache...) - return ret, nil + return ret } - return nil, nil + return nil } -func IcecastLastSong(playlistPath string) (*Song, error) { +func IcecastLastSong(playlistPath string) *Song { lastPlayedCacheMutex.Lock() defer lastPlayedCacheMutex.Unlock() if lpcLen := len(lastPlayedCache); lpcLen > 0 { - return &lastPlayedCache[lpcLen-1], nil + return &lastPlayedCache[lpcLen-1] } - return nil, nil + return nil } func icecastLastPlayedSongs(playlistPath string, n int) ([]Song, error) {