Skip to content

Commit 9a03665

Browse files
committed
Add an environment varialbe which disables the parsing of Go version from module file
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent b633c4c commit 9a03665

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

helpers.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
"strings"
3333
)
3434

35+
// noGoModVersion disables the parsing of go version from go module file present in the project
36+
const noGoModVersion = "GOSECNOMODVERSION"
37+
3538
// MatchCallByPackage ensures that the specified package is imported,
3639
// adjusts the name for any aliases and ignores cases that are
3740
// initialization only imports.
@@ -498,12 +501,13 @@ func RootPath(root string) (string, error) {
498501

499502
// GoVersion returns parsed version of Go mod version and fallback to runtime version if not found.
500503
func GoVersion() (int, int, int) {
501-
goVersion, err := goModVersion()
502-
if err != nil {
503-
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
504+
_, ok := os.LookupEnv(noGoModVersion)
505+
if ok {
506+
if goModVersion, err := goModVersion(); err == nil {
507+
return parseGoVersion(goModVersion)
508+
}
504509
}
505-
506-
return parseGoVersion(goVersion)
510+
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
507511
}
508512

509513
type goListOutput struct {

0 commit comments

Comments
 (0)