whatAmI := func(i interface{}) {
        switch t := i.(type) {
        case bool:
            fmt.Println("I'm a bool")
        case int:
            fmt.Println("I'm an int")
        default:
            fmt.Printf("Don't know type %T\n", t)
        }
    }
    whatAmI(true)  //bool
    whatAmI(1)     //int
    whatAmI("hey") //string

本文链接: http://ychda.cn/blog/article/golang-switch-1/