From 94d172cd13466cbef49c40cc23efdda2e345f32b Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 18 Mar 2022 22:23:31 -0400 Subject: cmd/cmd.go: add getCache() --- cmd/cmd.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 -- cgit v1.2.3