@@ -36,6 +36,15 @@ type GoModule struct {
36
36
Module * modfile.File // The parsed contents of the `go.mod` file
37
37
}
38
38
39
+ // Tries to find the Go toolchain version required for this module.
40
+ func (module * GoModule ) RequiredGoVersion () util.SemVer {
41
+ if module .Module != nil && module .Module .Go != nil {
42
+ return util .NewSemVer (module .Module .Go .Version )
43
+ } else {
44
+ return tryReadGoDirective (module .Path )
45
+ }
46
+ }
47
+
39
48
// Represents information about a Go project workspace: this may either be a folder containing
40
49
// a `go.work` file or a collection of `go.mod` files.
41
50
type GoWorkspace struct {
@@ -67,17 +76,10 @@ func (workspace *GoWorkspace) RequiredGoVersion() util.SemVer {
67
76
// Otherwise, if we have `go.work` files, find the greatest Go version in those.
68
77
var greatestVersion util.SemVer = nil
69
78
for _ , module := range workspace .Modules {
70
- if module .Module != nil && module .Module .Go != nil {
71
- // If we have parsed the file, retrieve the version number we have already obtained.
72
- modVersion := util .NewSemVer (module .Module .Go .Version )
73
- if greatestVersion == nil || modVersion .IsNewerThan (greatestVersion ) {
74
- greatestVersion = modVersion
75
- }
76
- } else {
77
- modVersion := tryReadGoDirective (module .Path )
78
- if modVersion != nil && (greatestVersion == nil || modVersion .IsNewerThan (greatestVersion )) {
79
- greatestVersion = modVersion
80
- }
79
+ modVersion := module .RequiredGoVersion ()
80
+
81
+ if modVersion != nil && (greatestVersion == nil || modVersion .IsNewerThan (greatestVersion )) {
82
+ greatestVersion = modVersion
81
83
}
82
84
}
83
85
0 commit comments