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
+28.6k Golang : Validate email address with regular expression
+10.7k Golang : convert rune to unicode hexadecimal value and back to rune character
+23.8k Golang : Change a file last modified date and time
+14.2k Golang : Qt image viewer example
+4.4k Linux/Unix : Commands that you need to be careful about
+15.2k Golang : Simple client server example
+31.6k Golang : Display float in 2 decimal points and rounding up or down
+9.6k Swift : Convert (cast) Int or int32 value to CGFloat
+4.4k Javascript : Generate random key with specific length
+9.8k Golang : Get user input until a command or receive a word to stop
+6.4k How to show different content from website server when AdBlock is detected?
+6k Findstr command the Grep equivalent for Windows