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
+8k Swift : Convert (cast) String to Float
+6.4k Golang : Selection sort example
+11.6k Swift : Convert (cast) Float to String
+15.6k Golang : Validate hostname
+14.5k Golang : On enumeration
+13.6k Golang : Count number of runes in string
+5.1k Golang : Constant and variable names in native language
+14.1k Golang : Reverse IP address for reverse DNS lookup example
+13.3k Golang : How to calculate the distance between two coordinates using Haversine formula
+10.2k Golang : Print how to use flag for your application example
+12.8k Golang : zlib compress file example