aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--feed/cveid.go5
-rw-r--r--feed/score.go10
-rw-r--r--feed/severity.go5
3 files changed, 20 insertions, 0 deletions
diff --git a/feed/cveid.go b/feed/cveid.go
index 5e43ad3..d7d9a32 100644
--- a/feed/cveid.go
+++ b/feed/cveid.go
@@ -75,6 +75,11 @@ func NewCveId(s string) (CveId, error) {
return CveId(encodeCveId(year, num)), nil
}
+// Marshal CVE ID to JSON.
+func (me CveId) MarshalJSON() ([]byte, error) {
+ return json.Marshal(me.String())
+}
+
// Unmarshal CVE ID from JSON.
func (me *CveId) UnmarshalJSON(b []byte) error {
// decode string, check for error
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())
+}
diff --git a/feed/severity.go b/feed/severity.go
index 50969ed..694b469 100644
--- a/feed/severity.go
+++ b/feed/severity.go
@@ -45,3 +45,8 @@ func (me *Severity) UnmarshalJSON(b []byte) error {
// return success
return nil
}
+
+// Marshal CVSS severity as JSON.
+func (me Severity) MarshalJSON() ([]byte, error) {
+ return json.Marshal(me.String())
+}