goversion
is a package that gets the go version from the go command.
Go 1.11 or later
See godoc examples.
package main
import (
"fmt"
"github.com/sg0hsmt/goversion"
)
func main() {
ver, err := goversion.Discover()
if err != nil {
fmt.Printf("discover failed: %v", err)
return
}
fmt.Printf("version: %s\n", ver)
fmt.Printf("major: %d\n", ver.Major)
fmt.Printf("minor: %d\n", ver.Minor)
fmt.Printf("patch: %d\n", ver.Patch)
if ver.IsPreRelease() {
fmt.Printf("pre: %q\n", ver.Pre)
}
}
go test .
You can use GitHub Actions locally by act.
act -j test
The development version (called gotip) is not supported.