Get operating system name in Go

January 3, 2015   

To get the operating system name where we running a Go program, we can use runtime package. runtime.GOOS return the operating system name. Some people try to use os.Getenv(“GOOS”) but it is not very reliable. I always use runtime package.

package main

import (

func main() {
	var goos string = runtime.GOOS
	fmt.Printf("The operating system is: %s\n", goos)