aboutsummaryrefslogtreecommitdiff
path: root/feed/datatype.go
blob: 6eaa1459297a547c7e9b71a38f7ab05fa9f5ab7c (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
35
36
package feed

//go:generate stringer -linecomment -type=DataType

import (
  "encoding/json"
  "fmt"
)

// Data type for NVD feeds and feed items.
type DataType byte

const (
  CveType DataType = iota // CVE
)

// Unmarshal DataType from JSON.
func (me *DataType) UnmarshalJSON(b []byte) error {
  // decode string, check for error
  var s string
  if err := json.Unmarshal(b, &s); err != nil {
    return err
  }

  // check value
  switch s {
  case "CVE":
    *me = CveType
  default:
    // return error
    return fmt.Errorf("unknown data type: %s", s)
  }

  // return success
  return nil
}