aboutsummaryrefslogtreecommitdiff
path: root/dbstore/cpesearchrow.go
blob: 87de9a8d11e84d11481a6584b065296572cf185b (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dbstore

import (
  db_sql "database/sql"
  "encoding/json"
  "github.com/pablotron/cvez/cpedict"
)

// title search result
type CpeSearchRow struct {
  // Database CPE ID
  CpeId int64 `json:"cpe_id"`

  // v2.3 formatting string
  Cpe23 string `json:"cpe23"`

  // titles
  Titles []cpedict.Title `json:"titles"`

  // references
  Refs []cpedict.Reference `json:"refs"`

  // search result rank
  Rank float32 `json:"rank"`
}

// Unmarshal CPE search row from row set.
func unmarshalCpeSearchRow(rows *db_sql.Rows) (CpeSearchRow, error) {
  var r CpeSearchRow
  var titles string
  var refs string

  // get row values
  if err := rows.Scan(&r.CpeId, &r.Cpe23, &titles, &refs, &r.Rank); err != nil {
    return r, err
  }

  // unmarshal titles
  if err := json.Unmarshal([]byte(titles), &r.Titles); err != nil {
    return r, err
  }

  // unmarshal refs
  if err := json.Unmarshal([]byte(refs), &r.Refs); err != nil {
    return r, err
  }

  // return sccess
  return r, nil
}