get system type in go

You can get the system type in Go by using the runtime.GOOS variable.

Here's an example code snippet:

main.go
package main

import (
    "fmt"
    "runtime"
)

func main() {
    fmt.Println("Operating System:", runtime.GOOS)
}
117 chars
11 lines

The above code will print the name of the operating system on which the program is running. This value will be one of the following:

  • darwin (macOS)
  • freebsd
  • linux
  • windows
  • netbsd
  • openbsd
  • plan9
  • dragonfly

Note that runtime.GOOS returns the operating system's official name, which may not always be the same as the user-friendly name.

related categories

gistlibby LogSnag