Skip to content

Commit e75bb92

Browse files
committed
cmd/go/internal/modload: don't infer a /v1 suffix module path
1 parent 13b1261 commit e75bb92

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/cmd/go/internal/modload/init.go

+10
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,15 @@ func findModulePath(dir string) (string, error) {
17101710
badPathErr = err
17111711
break
17121712
}
1713+
// Ensure the inferred path is valid.
1714+
if _, _, ok := module.SplitPathVersion(path); !ok {
1715+
if strings.HasPrefix(path, "gopkg.in/") {
1716+
badPathErr = errors.New("module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN")
1717+
} else {
1718+
badPathErr = errors.New("major version suffixes must be in the form of /vN and are only allowed for v2 or later")
1719+
}
1720+
break
1721+
}
17131722
return path, nil
17141723
}
17151724
}
@@ -1725,6 +1734,7 @@ func findModulePath(dir string) (string, error) {
17251734
Example usage:
17261735
'go mod init example.com/m' to initialize a v0 or v1 module
17271736
'go mod init example.com/m/v2' to initialize a v2 module
1737+
'go mod init gopkg.in/m.v1' to initialize a gopkg.in module
17281738
17291739
Run 'go help mod init' for more information.
17301740
`

0 commit comments

Comments
 (0)