aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-03-18 22:23:31 -0400
committerPaul Duncan <pabs@pablotron.org>2022-03-18 22:23:31 -0400
commit94d172cd13466cbef49c40cc23efdda2e345f32b (patch)
tree6ffc894797d56bee6ff64c34c283e92e16c3f9aa
parenta06e3362be691331215b10bdefc28a2db363563a (diff)
downloadcvez-94d172cd13466cbef49c40cc23efdda2e345f32b.tar.bz2
cvez-94d172cd13466cbef49c40cc23efdda2e345f32b.zip
cmd/cmd.go: add getCache()
-rw-r--r--cmd/cmd.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 4b09d18..80c1527 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -5,9 +5,11 @@ import (
"encoding/json"
"github.com/pablotron/cvez/datadir"
"github.com/pablotron/cvez/dbstore"
+ "github.com/pablotron/cvez/nvdmirror"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
+ "path/filepath"
"strings"
"time"
)
@@ -42,6 +44,26 @@ func getDb() dbstore.DbStore {
return db
}
+// Get cache.
+func getCache() nvdmirror.JsonCache {
+ // get path to cache directory
+ cacheDir, err := datadir.CacheDir()
+ if err != nil {
+ log.Error().Err(err).Msg("CacheDir")
+ os.Exit(-1)
+ }
+
+ // create cache
+ cache, err := nvdmirror.NewJsonCache(filepath.Join(cacheDir, "cache.json.gz"))
+ if err != nil {
+ log.Error().Err(err).Msg("NewJsonCache")
+ os.Exit(-1)
+ }
+
+ // return cache
+ return cache
+}
+
// JSON encode data and write it to standard output
func jsonEncode(data interface{}) {
// search for CVEs, write result