Retrieving the Golang version

While building a program, it is a good practice to log the environment settings, build version, and runtime version, especially if your application is more complex. This helps you to analyze the problem, in case something goes wrong.

Besides the build version and, for example, the environmental variables, the Go version by which the binary was compiled could be included in the log. The following recipe will show you how to include the Go runtime version into such program information.

package main

import (

const info = `
			 Application %s starting.
			 The binary was build by GO: %s`

func main() {
	log.Printf(info, "Example", runtime.Version())


Biradars-MacBook-Air-4:golang-daily sangam$ go run main.go 
2019/11/30 01:53:12 
			 Application Example starting.
			 The binary was build by GO: go1.13.4