Skip to content

Commit

Permalink
chore: adopt reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Jun 28, 2024
1 parent 867f0ed commit 638ba0c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions commands/fetchfortinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/spf13/viper"
"golang.org/x/xerrors"

db "github.com/vulsio/go-cve-dictionary/db"
"github.com/vulsio/go-cve-dictionary/db"
"github.com/vulsio/go-cve-dictionary/fetcher/fortinet"
log "github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
)

Expand Down
4 changes: 2 additions & 2 deletions commands/fetchjvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/spf13/viper"
"golang.org/x/xerrors"

db "github.com/vulsio/go-cve-dictionary/db"
log "github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/db"
"github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
)

Expand Down
7 changes: 4 additions & 3 deletions commands/fetchmitre.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
db "github.com/vulsio/go-cve-dictionary/db"
log "github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
"golang.org/x/xerrors"

"github.com/vulsio/go-cve-dictionary/db"
"github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
)

var fetchMitreCmd = &cobra.Command{
Expand Down
5 changes: 3 additions & 2 deletions commands/fetchnvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/xerrors"

"github.com/vulsio/go-cve-dictionary/db"
log "github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
"golang.org/x/xerrors"
)

var fetchNvdCmd = &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
log "github.com/vulsio/go-cve-dictionary/log"

"github.com/vulsio/go-cve-dictionary/log"
)

var cfgFile string
Expand Down
7 changes: 4 additions & 3 deletions commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package commands
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/xerrors"

"github.com/vulsio/go-cve-dictionary/db"
log "github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/log"
"github.com/vulsio/go-cve-dictionary/models"
server "github.com/vulsio/go-cve-dictionary/server"
"golang.org/x/xerrors"
"github.com/vulsio/go-cve-dictionary/server"
)

// serverCmd is Subcommand for CVE dictionary HTTP Server
Expand Down
1 change: 1 addition & 0 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/spf13/cobra"

"github.com/vulsio/go-cve-dictionary/config"
)

Expand Down
10 changes: 3 additions & 7 deletions fetcher/mitre/mitre.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,17 @@ func Fetch() (string, error) {
// Convert convert <cacheDir>/<year>/CVE-<year>-\d{4,}.json to []models.Mitre
func Convert(cacheDir, year string) ([]models.Mitre, error) {
var ps []string
if err := filepath.WalkDir(cacheDir, func(path string, d fs.DirEntry, err error) error {
if err := filepath.WalkDir(filepath.Join(cacheDir, year), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}

if strings.HasPrefix(filepath.Base(path), fmt.Sprintf("CVE-%s-", year)) {
ps = append(ps, path)
}

ps = append(ps, path)
return nil
}); err != nil {
return nil, xerrors.Errorf("Failed to walk %s. err: %w", cacheDir, err)
return nil, xerrors.Errorf("Failed to walk %s. err: %w", filepath.Join(cacheDir, year), err)
}

reqChan := make(chan string, len(ps))
Expand Down
10 changes: 3 additions & 7 deletions fetcher/nvd/nvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,17 @@ func Fetch() (string, error) {
// Convert convert <cacheDir>/<year>/CVE-<year>-\d{4,}.json to []models.Nvd
func Convert(cacheDir, year string) ([]models.Nvd, error) {
var ps []string
if err := filepath.WalkDir(cacheDir, func(path string, d fs.DirEntry, err error) error {
if err := filepath.WalkDir(filepath.Join(cacheDir, year), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}

if strings.HasPrefix(filepath.Base(path), fmt.Sprintf("CVE-%s-", year)) {
ps = append(ps, path)
}

ps = append(ps, path)
return nil
}); err != nil {
return nil, xerrors.Errorf("Failed to walk %s. err: %w", cacheDir, err)
return nil, xerrors.Errorf("Failed to walk %s. err: %w", filepath.Join(cacheDir, year), err)
}

reqChan := make(chan string, len(ps))
Expand Down

0 comments on commit 638ba0c

Please sign in to comment.