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
+4.7k Javascript : How to get width and height of a div?
+15.1k Golang : Get timezone offset from date or timestamp
+17.1k Golang : When to use init() function?
+18.9k Golang : Check whether a network interface is up on your machine
+8k Golang : How To Use Panic and Recover
+9.4k Golang : Extract or copy items from map based on value
+17.5k How to enable MariaDB/MySQL logs ?
+12.7k Golang : http.Get example
+16.9k Golang : Covert map/slice/array to JSON or XML format
+12.2k Golang : Encrypt and decrypt data with x509 crypto
+8.2k Useful methods to access blocked websites
+21.3k Golang : How to read float value from standard input ?