@@ -367,8 +367,15 @@ func getDepMode(emitDiagnostics bool) (DependencyInstallerMode, string) {
367
367
return GoGetNoModules , "."
368
368
}
369
369
370
+ type GoVersionInfo struct {
371
+ // The version string, if any
372
+ Version string
373
+ // A value indicating whether a version string was found
374
+ Found bool
375
+ }
376
+
370
377
// Tries to open `go.mod` and read a go directive, returning the version and whether it was found.
371
- func tryReadGoDirective (buildInfo BuildInfo ) ( string , bool ) {
378
+ func tryReadGoDirective (buildInfo BuildInfo ) GoVersionInfo {
372
379
if buildInfo .DepMode == GoGetWithModules {
373
380
versionRe := regexp .MustCompile (`(?m)^go[ \t\r]+([0-9]+\.[0-9]+(\.[0-9]+)?)$` )
374
381
goMod , err := os .ReadFile (filepath .Join (buildInfo .BaseDir , "go.mod" ))
@@ -378,12 +385,12 @@ func tryReadGoDirective(buildInfo BuildInfo) (string, bool) {
378
385
matches := versionRe .FindSubmatch (goMod )
379
386
if matches != nil {
380
387
if len (matches ) > 1 {
381
- return string (matches [1 ]), true
388
+ return GoVersionInfo { string (matches [1 ]), true }
382
389
}
383
390
}
384
391
}
385
392
}
386
- return "" , false
393
+ return GoVersionInfo { "" , false }
387
394
}
388
395
389
396
// Returns the appropriate ModMode for the current project
@@ -771,13 +778,13 @@ func installDependenciesAndBuild() {
771
778
os .Setenv ("GO111MODULE" , "auto" )
772
779
}
773
780
774
- goModVersion , goModVersionFound := tryReadGoDirective (buildInfo )
781
+ goVersionInfo := tryReadGoDirective (buildInfo )
775
782
776
- if goModVersionFound && semver .Compare ("v" + goModVersion , getEnvGoSemVer ()) > 0 {
783
+ if goVersionInfo . Found && semver .Compare ("v" + goVersionInfo . Version , getEnvGoSemVer ()) > 0 {
777
784
diagnostics .EmitNewerGoVersionNeeded ()
778
785
}
779
786
780
- fixGoVendorIssues (& buildInfo , goModVersionFound )
787
+ fixGoVendorIssues (& buildInfo , goVersionInfo . Found )
781
788
782
789
tryUpdateGoModAndGoSum (buildInfo )
783
790
@@ -1092,7 +1099,8 @@ func isGoInstalled() bool {
1092
1099
func identifyEnvironment () {
1093
1100
var v versionInfo
1094
1101
buildInfo := getBuildInfo (false )
1095
- v .goModVersion , v .goModVersionFound = tryReadGoDirective (buildInfo )
1102
+ goVersionInfo := tryReadGoDirective (buildInfo )
1103
+ v .goModVersion , v .goModVersionFound = goVersionInfo .Version , goVersionInfo .Found
1096
1104
1097
1105
v .goEnvVersionFound = isGoInstalled ()
1098
1106
if v .goEnvVersionFound {
0 commit comments