1
0

Removed unused error returning (error is always nil).

This commit is contained in:
Alexander Andreev 2023-09-14 17:59:14 +04:00
parent a6f92b56da
commit 978b4c6454
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 9 additions and 15 deletions

View File

@ -32,10 +32,8 @@ func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) {
log.Println("failed to get Icecast status:", err) log.Println("failed to get Icecast status:", err)
} }
songs, err := radio.IcecastLastSongs(h.icecastPlaylistPath) songs := radio.IcecastLastSongs(h.icecastPlaylistPath)
if err != nil { if songs != nil {
log.Println("cannot retrieve last songs:", err)
} else {
for i := 0; i < len(songs); i++ { for i := 0; i < len(songs); i++ {
if tim, err := time.Parse(radio.SongTimeFormat, songs[i].Time); err == nil { if tim, err := time.Parse(radio.SongTimeFormat, songs[i].Time); err == nil {
songs[i].Time = utils.ToClientTimezone(tim, r).Format("15:04") 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) { func (h *Handlers) LastSong(w http.ResponseWriter, r *http.Request) {
song, err := radio.IcecastLastSong(h.icecastPlaylistPath) song := radio.IcecastLastSong(h.icecastPlaylistPath)
if err != nil {
log.Println("cannot retrieve last songs:", err)
}
if song == nil { if song == nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return

View File

@ -76,25 +76,25 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) {
}, nil }, nil
} }
func IcecastLastSongs(playlistPath string) ([]Song, error) { func IcecastLastSongs(playlistPath string) []Song {
lastPlayedCacheMutex.Lock() lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock() defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 { if lpcLen := len(lastPlayedCache); lpcLen > 0 {
ret := make([]Song, 0, lpcLen) ret := make([]Song, 0, lpcLen)
ret = append(ret, lastPlayedCache...) 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() lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock() defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 { 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) { func icecastLastPlayedSongs(playlistPath string, n int) ([]Song, error) {