switch 接收命令行參數測試
package main import ( "fmt" "os" ) func main() { // os.Args[0] 爲程序帶路徑的名稱 // os.Args[1] 爲第一個參數 args := os.Args if len(args) < 2 { fmt.Println("param error.") } switch args[1] { case "hello": fmt.Println("hello") case "world": fmt.Println("world") default: fmt.Println("default") } }
測試ui
go build -o test.exe switch.go ./test.exe hello world wu test