diff options
Diffstat (limited to 'dbstore/cpesearchrow.go')
-rw-r--r-- | dbstore/cpesearchrow.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/dbstore/cpesearchrow.go b/dbstore/cpesearchrow.go new file mode 100644 index 0000000..87de9a8 --- /dev/null +++ b/dbstore/cpesearchrow.go @@ -0,0 +1,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 +} |