github.com/eh-steve/goloader@v0.0.0-20240111193454-90ff3cfdae39/goversion/version.go (about)

     1  package goversion
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"strconv"
     7  	"strings"
     8  )
     9  
    10  func GoVersion() int64 {
    11  	GoVersionParts := strings.Split(strings.TrimPrefix(runtime.Version(), "go"), ".")
    12  	stripRC := strings.Split(GoVersionParts[1], "rc")[0] // Treat release candidates as if they are that version
    13  	version, err := strconv.ParseInt(stripRC, 10, 64)
    14  	if err != nil {
    15  		panic(fmt.Sprintf("failed to parse go version: %s", err))
    16  	}
    17  	return version
    18  }