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
+13k Golang : Get terminal width and height example
+12.3k Golang : Display list of countries and ISO codes
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+8.2k Golang : Emulate NumPy way of creating matrix example
+8.1k Golang : Multiplexer with net/http and map
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+25.9k Golang : How to read integer value from standard input ?
+5.3k PHP : Hide PHP version information from curl
+36.5k Golang : Validate IP address
+5.3k Golang : Pad file extension automagically
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?