aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/vector.go
blob: a326c85eb3714ceb8b7bf665b68b3940a4db4f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}