1
0

In MarshalJSON() for Song a string field Duration was removed, just msec left.

This commit is contained in:
Alexander Andreev 2023-10-07 05:11:58 +04:00
parent 62f6e3b976
commit 1d50bbe790
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -34,14 +34,12 @@ func (s *Song) MarshalJSON() ([]byte, error) {
Artist string `json:"artist"` Artist string `json:"artist"`
Title string `json:"title"` Title string `json:"title"`
DurationMill int64 `json:"duration_msec"` DurationMill int64 `json:"duration_msec"`
Duration string `json:"duration"`
MaxListeners int `json:"listeners"` MaxListeners int `json:"listeners"`
StartAt string `json:"start_at"` StartAt string `json:"start_at"`
}{ }{
Artist: s.Artist, Artist: s.Artist,
Title: s.Title, Title: s.Title,
DurationMill: s.Duration.Milliseconds(), DurationMill: s.Duration.Milliseconds(),
Duration: s.DurationString(),
MaxListeners: s.MaxListeners, MaxListeners: s.MaxListeners,
StartAt: s.StartAt.UTC().Format(time.RFC3339)}) StartAt: s.StartAt.UTC().Format(time.RFC3339)})
} }
@ -77,13 +75,13 @@ func (sl *SongList) Add(newSong Song) {
} }
// Current returns a currently playing song. // Current returns a currently playing song.
func (sl *SongList) Current() Song { func (sl *SongList) Current() *Song {
sl.Lock() sl.Lock()
defer sl.Unlock() defer sl.Unlock()
if sl.current.StartAt.Year() == 1 { if sl.current.StartAt.Year() == 1 {
return Song{} return nil
} }
return sl.current return &sl.current
} }
// UpdateCurrentMaxListeners checks and updates a maximal number of listeners // UpdateCurrentMaxListeners checks and updates a maximal number of listeners