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
+31.2k Golang : Smarter Error Handling with strings.Contains()
+14.4k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+5k Golang : Function as an argument type example
+11.3k Golang : Remove or trim extra comma from CSV
+9.7k PHP : Convert(cast) bigInt to string
+21.5k Golang : Get ASCII code from a key press(cross-platform) example
+4.4k Golang : Generate Interleaved 2 inch by 5 inch barcode
+17.7k Golang : Delete duplicate items from a slice/array
+5.8k Golang : Pat multiplexer routing example
+6.7k Golang : How to execute code at certain day, hour and minute?
+11.7k Golang : Convert(cast) uintptr to string example
+8.2k Golang : Scramble and unscramble text message by randomly replacing words