diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-03-18 22:23:31 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-03-18 22:23:31 -0400 |
commit | 94d172cd13466cbef49c40cc23efdda2e345f32b (patch) | |
tree | 6ffc894797d56bee6ff64c34c283e92e16c3f9aa | |
parent | a06e3362be691331215b10bdefc28a2db363563a (diff) | |
download | cvez-94d172cd13466cbef49c40cc23efdda2e345f32b.tar.bz2 cvez-94d172cd13466cbef49c40cc23efdda2e345f32b.zip |
cmd/cmd.go: add getCache()
-rw-r--r-- | cmd/cmd.go | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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 |