1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| package main
import ( "runtime" "fmt" )
func IfDemo() { OSName := runtime.GOOS if OSName == "windows" { fmt.Println("It's Windows") } else if OSName == "linux" { fmt.Println("It's Linux🐧") } else if OSName == "darwin" { fmt.Println("It's MacOS🍎") } else { fmt.Println("Other OS") }
if OSArch := runtime.GOARCH; OSArch == "amd64" { fmt.Println("64位操作系统❗️") } else if OSArch == "amd32" { fmt.Println("32位操作系统❗️️") } else { fmt.Println("什么鬼❓") } }
func SwitchDemo() { OSName := runtime.GOOS switch OSName { case "windows": fmt.Println("It's Windows") case "linux": fmt.Println("It's Linux🐧") case "darwin": fmt.Println("It's MacOS🍎") case "unix", "ios", "android": fmt.Println("🙃") default: fmt.Println("什么鬼❓") }
OSArch := runtime.GOARCH switch { case OSArch == "amd64": fmt.Println("64位操作系统❗️") case OSArch == "amd32": fmt.Println("32位操作系统❗️") default: fmt.Println("什么鬼❓") } }
func main() { IfDemo() SwitchDemo() }
|