How to retrieve the Go version at runtime using the runtime package in Golang?

To retrieve the Go version at runtime using the runtime package in Go, you can make use of the runtime.Version() function. Here's an example:

package main import ( "fmt" "runtime" ) func main() { goVersion := runtime.Version() fmt.Println("Go version:", goVersion) }

Output:

Go version: go1.17.2

In this example, we import the runtime package and call the runtime.Version() function to retrieve the Go version. The returned string represents the current Go version being used.