aboutsummaryrefslogtreecommitdiff
path: root/feed/score.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-03-19 07:42:10 -0400
committerPaul Duncan <pabs@pablotron.org>2022-03-19 07:42:10 -0400
commit8b9e4eeead8717974d34839c7b32cf9324b860db (patch)
tree1dabbb8b001b4b75377f7023d8a93c1cff2c7df9 /feed/score.go
parent5ae828ed1feb978dc24acc8545c4d56b4262a7f5 (diff)
downloadcvez-8b9e4eeead8717974d34839c7b32cf9324b860db.tar.bz2
cvez-8b9e4eeead8717974d34839c7b32cf9324b860db.zip
feed: add MarshalJSON for several types
Diffstat (limited to 'feed/score.go')
-rw-r--r--feed/score.go10
1 files changed, 10 insertions, 0 deletions
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())
+}