aboutsummaryrefslogtreecommitdiff
path: root/dbstore/cpesearchrow.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-05 11:06:55 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-05 11:06:55 -0500
commit63a3351c9527f9f774862329b56f487339b09903 (patch)
tree2b43ecb72cc930fa1e84d843f96f6138dd84e8b4 /dbstore/cpesearchrow.go
parenta6d72e2f75064a3ab823449c912188d210a77feb (diff)
downloadcvez-63a3351c9527f9f774862329b56f487339b09903.tar.bz2
cvez-63a3351c9527f9f774862329b56f487339b09903.zip
dbstore: refactor, separate cpesearchrow and cpesearchtype, add cpesearchtype_test
Diffstat (limited to 'dbstore/cpesearchrow.go')
-rw-r--r--dbstore/cpesearchrow.go50
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
+}