diff options
Diffstat (limited to 'internal/feed/vector.go')
-rw-r--r-- | internal/feed/vector.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/feed/vector.go b/internal/feed/vector.go new file mode 100644 index 0000000..a326c85 --- /dev/null +++ b/internal/feed/vector.go @@ -0,0 +1,34 @@ +// NVD JSON feed parser. +package feed + +import ( + "encoding/json" + "nvd/internal/cvss" +) + +// CVSS vector +type Vector struct { + // CVSS vector + Vector cvss.Vector +} + +// Unmarshal CVSS score from JSON. +func (me *Vector) UnmarshalJSON(b []byte) error { + // decode string, check for error + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + + // parse vector + vec, err := cvss.NewVector(s) + if err != nil { + return err + } + + // save result + me.Vector = vec + + // return success + return nil +} |