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
+18.3k Golang : How to Set or Add Header http.ResponseWriter?
+17.2k Golang : Generate thumbnails from images
+15.4k Golang : read gzipped http response
+16.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+6k Golang : Get Alexa ranking data example
+12.5k Golang : unknown escape sequence error
+50.4k Golang : How to get struct field and value by name
+13.3k Golang : How to filter a map's elements for faster lookup
+3.9k PHP : Extract part of a string starting from the middle
+3.9k JQuery : Calling a function inside Jquery(document) block
+18.5k Android Studio : AlertDialog and EditText to get user string input example
+12.9k Golang : Convert IP version 6 address to integer or decimal number