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
+16.1k Golang : How to extract links from web page ?
+9.3k Golang : Play .WAV file from command line
+8.9k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+19.4k Golang : Example for DSA(Digital Signature Algorithm) package functions
+21k Golang : Create and resolve(read) symbolic links
+6k Golang : Dealing with backquote
+6.7k Android Studio : Hello World example
+4.9k Golang : PGX CopyFrom to insert rows into Postgres database
+15.8k Golang : Update database with GORM example
+7.2k Linux : How to fix Brother HL-1110 printing blank page problem
+5.7k Golang : Error handling methods
+7k Golang : Array mapping with Interface