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.6k MariaDB/MySQL : How to get version information
+16.5k Golang : File path independent of Operating System
+6.9k How to let Facebook Login button redirect to a particular URL ?
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+10.6k Golang : Flip coin example
+18.7k Golang : Implement getters and setters
+14.6k Golang : Execute function at intervals or after some delay
+4.7k Adding Skype actions such as call and chat into web page examples
+13.7k Golang : Check if an integer is negative or positive
+6.9k Golang : Decode XML data from RSS feed
+19.4k Golang : How to count the number of repeated characters in a string?
+18k Golang : How to log each HTTP request to your web server?