From ad73986070f4dfc30887cbf9b01f86d7eb914597 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 14 Aug 2021 15:32:28 +0200 Subject: [PATCH] goenv: improve Go version detection First look at the VERSION file, only then look at src/runtime/internal/sys/zversion.go. This makes it possible to correctly detect the Go version for release candidates. --- goenv/version.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/goenv/version.go b/goenv/version.go index e0fe0949..87752a01 100644 --- a/goenv/version.go +++ b/goenv/version.go @@ -48,7 +48,10 @@ func GetGorootVersion(goroot string) (major, minor int, err error) { // toolchain for the given GOROOT path. It is usually of the form `go1.x.y` but // can have some variations (for beta releases, for example). func GorootVersionString(goroot string) (string, error) { - if data, err := ioutil.ReadFile(filepath.Join( + if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil { + return string(data), nil + + } else if data, err := ioutil.ReadFile(filepath.Join( goroot, "src", "runtime", "internal", "sys", "zversion.go")); err == nil { r := regexp.MustCompile("const TheVersion = `(.*)`") @@ -59,9 +62,6 @@ func GorootVersionString(goroot string) (string, error) { return string(matches[1]), nil - } else if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil { - return string(data), nil - } else { return "", err }