feat: add concurrency option to parallelize package loading (#778)

* feat: add concurrency option to parallelize package loading

* refactor: move wg.add inside the for loop

* fix: gracefully stop the workers on error

* test: add test for concurrent scan
This commit is contained in:
kruskal
2022-02-16 18:23:37 +01:00
committed by GitHub
parent 43577cebb7
commit 7d539ed494
4 changed files with 96 additions and 17 deletions

View File

@@ -20,6 +20,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
"sort"
"strings"
@@ -114,6 +115,9 @@ var (
// fail by confidence
flagConfidence = flag.String("confidence", "low", "Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high")
// concurrency value
flagConcurrency = flag.Int("concurrency", runtime.NumCPU(), "Concurrency value")
// do not fail
flagNoFail = flag.Bool("no-fail", false, "Do not fail the scanning, even if issues were found")
@@ -371,7 +375,7 @@ func main() {
}
// Create the analyzer
analyzer := gosec.NewAnalyzer(config, *flagScanTests, *flagExcludeGenerated, *flagTrackSuppressions, logger)
analyzer := gosec.NewAnalyzer(config, *flagScanTests, *flagExcludeGenerated, *flagTrackSuppressions, *flagConcurrency, logger)
analyzer.LoadRules(ruleList.RulesInfo())
excludedDirs := gosec.ExcludedDirsRegExp(flagDirsExclude)