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 ( import (
"bytes" "bytes"
"encoding/json"
"errors" "errors"
"strconv" "strconv"
"time" "time"
@ -21,6 +22,17 @@ func (mls *MostListenedSong) DateString() string {
return mls.Date.Format(MostListenedDateFormat) 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 var mostListened MostListenedSong
// CheckAndUpdateMostListenedSong compares current most played song with // CheckAndUpdateMostListenedSong compares current most played song with