@@ -47,6 +47,7 @@ variable is 32.
47
47
48
48
var goVersion = ""
49
49
50
+ // Returns the current Go version as returned by 'go version', e.g. go1.14.4
50
51
func getEnvGoVersion () string {
51
52
if goVersion == "" {
52
53
gover , err := exec .Command ("go" , "version" ).CombinedOutput ()
@@ -58,6 +59,15 @@ func getEnvGoVersion() string {
58
59
return goVersion
59
60
}
60
61
62
+ // Returns the current Go version in semver format, e.g. v1.14.4
63
+ func getEnvGoSemVer () string {
64
+ goVersion := getEnvGoVersion ()
65
+ if ! strings .HasPrefix (goVersion , "go" ) {
66
+ log .Fatalf ("Expected 'go version' output of the form 'go1.2.3'; got '%s'" , goVersion )
67
+ }
68
+ return "v" + goVersion [2 :]
69
+ }
70
+
61
71
func run (cmd * exec.Cmd ) bool {
62
72
cmd .Stdout = os .Stdout
63
73
cmd .Stderr = os .Stderr
@@ -164,11 +174,12 @@ func (m ModMode) argsForGoVersion(version string) []string {
164
174
case ModReadonly :
165
175
return []string {"-mod=readonly" }
166
176
case ModMod :
167
- if semver .Compare (getEnvGoVersion (), "1.14" ) < 0 {
168
- log .Printf ("%s < %s" , getEnvGoVersion (), "1.14" )
177
+ if ! semver .IsValid (version ) {
178
+ log .Fatalf ("Invalid Go semver: '%s'" , version )
179
+ }
180
+ if semver .Compare (version , "v1.14" ) < 0 {
169
181
return []string {} // -mod=mod is the default behaviour for go <= 1.13, and is not accepted as an argument
170
182
} else {
171
- log .Printf ("%s >= %s" , getEnvGoVersion (), "1.14" )
172
183
return []string {"-mod=mod" }
173
184
}
174
185
case ModVendor :
@@ -505,7 +516,7 @@ func main() {
505
516
506
517
extractorArgs := []string {}
507
518
if depMode == GoGetWithModules {
508
- extractorArgs = append (extractorArgs , modMode .argsForGoVersion (getEnvGoVersion ())... )
519
+ extractorArgs = append (extractorArgs , modMode .argsForGoVersion (getEnvGoSemVer ())... )
509
520
}
510
521
extractorArgs = append (extractorArgs , "./..." )
511
522
0 commit comments