Added MarshalJSON() method to MostListenedSong.
This commit is contained in:
parent
ddf5f3d0f7
commit
3ed0f7b62a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user