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
+21.6k Golang : Read a file into an array or slice example
+6.8k Gogland : Single File versus Go Application Run Configurations
+4.1k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+8.6k Golang : Accessing content anonymously with Tor
+5.4k Golang : Debug with Godebug
+15.6k CodeIgniter/PHP : Create directory if does not exist example
+4.4k Golang : Pad file extension automagically
+5.3k Golang : How to write backslash in string?
+5k Unix/Linux : How to test user agents blocked successfully ?
+7.8k Golang : Set or add headers for many or different handlers
+5.2k Fontello : How to load and use fonts?
+5k nginx : force all pages to be SSL