Golang : Detect (OS) Operating System
Ability to detect which type of operating system during run time can be helpful in programming a software behavior or prompt different output message to the user.
Go has build in function to detect the operating system and able to tell you the type of operating system is Windows or Unix/Linux during run time.
To detect the operating system, use the runtime.GOOS
For example :
Detect Windows
if runtime.GOOS == 'windows' {
fmt.Println('Windows OS detected')
}
Detect Linux
if runtime.GOOS == 'linux' { // also can be specified to FreeBSD
fmt.Println('Unix/Linux type OS detected')
}
Detect Mac OS/X
if runtime.GOOS == 'darwin' {
fmt.Println('Mac OS detected')
}
references:
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.6k Golang : How to detect a server/machine network interface capabilities?
+12.9k Golang : Get terminal width and height example
+12.7k Golang : Convert int(year) to time.Time type
+8.7k Golang : Gorilla web tool kit schema example
+5.7k Unix/Linux : How to test user agents blocked successfully ?
+6.5k Golang : Combine slices of complex numbers and operation example
+9.9k Golang : Translate language with language package example
+7k Golang : Gargish-English language translator
+12.4k Golang : "https://" not allowed in import path
+5.7k Golang : Struct field tags and what is their purpose?
+9.1k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+5.7k Get website traffic ranking with Similar Web or Alexa