diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 82bdb6d..9ec40a5 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -62,31 +62,29 @@ func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) { status, err := radio.IcecastGetStatus(h.conf.Icecast.URL) if err != nil { h.logErr.Println("failed to get Icecast status:", err) - status = &radio.IcecastStatus{} - return + } else { + if tim, err := time.Parse(time.RFC1123Z, status.ServerStartDate); err == nil { + status.ServerStartDate = utils.ToClientTimezone(tim, r).Format(time.RFC1123) + } + + if tim, err := time.Parse(FormatISO8601, status.ServerStartISO8601); err == nil { + status.ServerStartISO8601 = utils.ToClientTimezone(tim, r).Format(FormatISO8601) + } } songs, err := radio.IcecastLastPlayedSongs(h.conf.ListLastNSongs, h.conf.Icecast.Playlist) if err != nil { h.logErr.Println("cannot retrieve last songs:", err) - } - - if tim, err := time.Parse(time.RFC1123Z, status.ServerStartDate); err == nil { - status.ServerStartDate = utils.ToClientTimezone(tim, r).Format(time.RFC1123) - } - - if tim, err := time.Parse(FormatISO8601, status.ServerStartISO8601); err == nil { - status.ServerStartISO8601 = utils.ToClientTimezone(tim, r).Format(FormatISO8601) - } - - 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") + } else { + 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") + } } } - if err := compiledTemplates["index"].Execute(w, &IndexData{ + if err := web.Template("index").Execute(w, &IndexData{ MainSite: utils.MainSite(r.Host), Status: status, Songs: songs,