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
+24.2k Golang : Find biggest/largest number in array
+7.2k Golang : A simple forex opportunities scanner
+7.8k Golang : Error reading timestamp with GORM or SQL driver
+31.8k Golang : bufio.NewReader.ReadLine to read file line by line
+28.8k Golang : Change a file last modified date and time
+11.3k Google Maps URL parameters configuration
+15.8k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+16.1k Golang : How to login and logout with JWT example
+6k Golang : Detect variable or constant type
+10.4k Golang : Detect number of faces or vehicles in a photo
+14k Golang : Convert spaces to tabs and back to spaces example
+12.9k Golang : flag provided but not defined error