1
0

Added MarshalJSON() method to MostListenedSong.

This commit is contained in:
Alexander Andreev 2023-10-02 02:07:39 +04:00
parent ddf5f3d0f7
commit 3ed0f7b62a
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -2,6 +2,7 @@ package radio
import (
"bytes"
"encoding/json"
"errors"
"strconv"
"time"
@ -21,6 +22,17 @@ func (mls *MostListenedSong) DateString() string {
return mls.Date.Format(MostListenedDateFormat)
}
func (mls *MostListenedSong) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Song string `json:"song"`
Listeners int `json:"listeners"`
Date string `json:"date"`
}{
Song: mls.Song,
Listeners: mls.Listeners,
Date: mls.Date.UTC().Format(time.RFC3339)})
}
var mostListened MostListenedSong
// CheckAndUpdateMostListenedSong compares current most played song with