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
+13.6k Facebook PHP getUser() returns 0
+6.4k Javascript : Generate random key with specific length
+41.5k Golang : Convert string to array/slice
+7k Golang : Normalize email to prevent multiple signups example
+7.4k Golang : Of hash table and hash map
+8.3k Golang : Get final or effective URL with Request.URL example
+6k Golang : Denco multiplexer example
+7.8k Golang : Error reading timestamp with GORM or SQL driver
+7.6k Golang : Create zip/ePub file without compression(use Store algorithm)
+5.5k Golang : What is StructTag and how to get StructTag's value?
+24.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+6.5k CodeIgniter : form input set_value cause " to become & quot