From 8b9e4eeead8717974d34839c7b32cf9324b860db Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 19 Mar 2022 07:42:10 -0400 Subject: feed: add MarshalJSON for several types --- feed/score.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'feed/score.go') diff --git a/feed/score.go b/feed/score.go index 9a03c50..30bb398 100644 --- a/feed/score.go +++ b/feed/score.go @@ -44,3 +44,13 @@ func (me Score) String() string { val := float64(me) / 10.0 return strconv.FormatFloat(val, 'f', 1, 64) } + +// Return floating point representation of score. +func (s Score) Float() float32 { + return float32(s) / 10.0 +} + +// Marshal score as JSON. +func (s Score) MarshalJSON() ([]byte, error) { + return json.Marshal(s.Float()) +} -- cgit v1.2.3