mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 12:05:52 +00:00
Add an environment varialbe which disables the parsing of Go version from module file
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
This commit is contained in:
parent
b633c4c0ec
commit
9a036658b7
1 changed files with 9 additions and 5 deletions
14
helpers.go
14
helpers.go
|
@ -32,6 +32,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// noGoModVersion disables the parsing of go version from go module file present in the project
|
||||||
|
const noGoModVersion = "GOSECNOMODVERSION"
|
||||||
|
|
||||||
// MatchCallByPackage ensures that the specified package is imported,
|
// MatchCallByPackage ensures that the specified package is imported,
|
||||||
// adjusts the name for any aliases and ignores cases that are
|
// adjusts the name for any aliases and ignores cases that are
|
||||||
// initialization only imports.
|
// initialization only imports.
|
||||||
|
@ -498,12 +501,13 @@ func RootPath(root string) (string, error) {
|
||||||
|
|
||||||
// GoVersion returns parsed version of Go mod version and fallback to runtime version if not found.
|
// GoVersion returns parsed version of Go mod version and fallback to runtime version if not found.
|
||||||
func GoVersion() (int, int, int) {
|
func GoVersion() (int, int, int) {
|
||||||
goVersion, err := goModVersion()
|
_, ok := os.LookupEnv(noGoModVersion)
|
||||||
if err != nil {
|
if ok {
|
||||||
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
|
if goModVersion, err := goModVersion(); err == nil {
|
||||||
|
return parseGoVersion(goModVersion)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return parseGoVersion(goVersion)
|
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
|
||||||
}
|
}
|
||||||
|
|
||||||
type goListOutput struct {
|
type goListOutput struct {
|
||||||
|
|
Loading…
Reference in a new issue