Advertisement
cwchen

[Go] Judging current system with switch

Sep 14th, 2017
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.32 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "runtime"
  6. )
  7.  
  8. func main() {
  9.     fmt.Print("Go runs on ")
  10.     os := runtime.GOOS
  11.     switch os {
  12.     case "windows":
  13.         fmt.Println("Windows")
  14.     case "darwin":
  15.         fmt.Println("Mac")
  16.     case "linux":
  17.         fmt.Println("GNU/Linux")
  18.     default:
  19.         // freebsd, openbsd, plan9...
  20.         fmt.Printf("%s.", os)
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement