Home » Core Golang » How to detect OS in Golang

How to detect OS in Golang

This article shows a handy Golang file at runtime to detect which type of operating system (OS) you are using now. We use runtime package of GO to find the OS at runtime .

package main

import (

func main() {
	if runtime.GOOS == "windows" {
		fmt.Println("Hello from Windows")

All possible GOOS values are defined in src/go/build/syslist.go. Those values are :

const goosList = "aix android darwin dragonfly freebsd hurd illumos ios js linux nacl netbsd openbsd plan9 solaris windows zos "


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top