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
+26.7k Golang : Encrypt and decrypt data with AES crypto
+11.4k Golang : Characters limiter example
+14.7k Golang : Overwrite previous output with count down timer
+12.2k Golang : Find and draw contours with OpenCV example
+33.7k Golang : How to check if slice or array is empty?
+7.4k Golang : File system scanning
+6.1k Golang : Compound interest over time example
+10k Golang : Turn string or text file into slice example
+13.3k Golang : Convert(cast) int to int64
+13.4k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+23.7k Golang : Read a file into an array or slice example
+9.6k Mac OSX : Get a process/daemon status information