@@ -252,6 +252,31 @@ func getDepMode() DependencyInstallerMode {
252
252
return GoGetNoModules
253
253
}
254
254
255
+ func tryReadGoDirective (depMode DependencyInstallerMode ) (string , bool ) {
256
+ version := ""
257
+ found := false
258
+ if depMode == GoGetWithModules {
259
+ versionRe := regexp .MustCompile (`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$` )
260
+ goMod , err := os .ReadFile ("go.mod" )
261
+ if err != nil {
262
+ log .Println ("Failed to read go.mod to check for missing Go version" )
263
+ } else {
264
+ matches := versionRe .FindSubmatch (goMod )
265
+ if matches != nil {
266
+ found = true
267
+ if len (matches ) > 1 {
268
+ version := string (matches [1 ])
269
+ semverVersion := "v" + version
270
+ if semver .Compare (semverVersion , getEnvGoSemVer ()) >= 0 {
271
+ diagnostics .EmitNewerGoVersionNeeded ()
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ return version , found
278
+ }
279
+
255
280
func getModMode (depMode DependencyInstallerMode ) ModMode {
256
281
if depMode == GoGetWithModules {
257
282
// if a vendor/modules.txt file exists, we assume that there are vendored Go dependencies, and
@@ -612,28 +637,11 @@ func installDependenciesAndBuild() {
612
637
// determine how to install dependencies and whether a GOPATH needs to be set up before
613
638
// extraction
614
639
depMode := getDepMode ()
615
- goDirectiveFound := false
616
640
if _ , present := os .LookupEnv ("GO111MODULE" ); ! present {
617
641
os .Setenv ("GO111MODULE" , "auto" )
618
642
}
619
- if depMode == GoGetWithModules {
620
- versionRe := regexp .MustCompile (`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$` )
621
- goMod , err := os .ReadFile ("go.mod" )
622
- if err != nil {
623
- log .Println ("Failed to read go.mod to check for missing Go version" )
624
- } else {
625
- matches := versionRe .FindSubmatch (goMod )
626
- if matches != nil {
627
- goDirectiveFound = true
628
- if len (matches ) > 1 {
629
- goDirectiveVersion := "v" + string (matches [1 ])
630
- if semver .Compare (goDirectiveVersion , getEnvGoSemVer ()) >= 0 {
631
- diagnostics .EmitNewerGoVersionNeeded ()
632
- }
633
- }
634
- }
635
- }
636
- }
643
+
644
+ _ , goDirectiveFound := tryReadGoDirective (depMode )
637
645
638
646
modMode := getModMode (depMode )
639
647
modMode = fixGoVendorIssues (modMode , depMode , goDirectiveFound )
0 commit comments