support to parse devl version

Signed-off-by: sivchari <shibuuuu5@gmail.com>
This commit is contained in:
sivchari
2024-11-15 15:39:22 +09:00
committed by Ayke
parent 258dac2324
commit ac9f72be61
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -50,6 +50,9 @@ func GetGorootVersion() (major, minor int, err error) {
// major, minor, and patch version: 1, 3, and 2 in this example.
// If there is an error, (0, 0, 0) and an error will be returned.
func Parse(version string) (major, minor, patch int, err error) {
if strings.HasPrefix(version, "devel ") {
version = strings.Split(strings.TrimPrefix(version, "devel "), version)[0]
}
if version == "" || version[:2] != "go" {
return 0, 0, 0, errors.New("could not parse Go version: version does not start with 'go' prefix")
}
+1
View File
@@ -21,6 +21,7 @@ func TestParse(t *testing.T) {
{"go1.23.5-rc6", 1, 23, 5, false},
{"go2.0", 2, 0, 0, false},
{"go2.0.15", 2, 0, 15, false},
{"devel go1.24-f99f5da18f Thu Nov 14 22:29:26 2024 +0000 darwin/arm64", 1, 24, 0, false},
}
for _, tt := range tests {
t.Run(tt.v, func(t *testing.T) {