How to check if interface{} is a slice
问题 I'm noob in Go :) so my question may be stupid, but can't find answer, so. I need a function: func name (v interface{}) { if is_slice() { for _, i := range v { my_var := i.(MyInterface) ... do smth } } else { my_var := v.(MyInterface) ... do smth } } How can I do is_slice in Go? Appreciate any help. 回答1: In your case the type switch is the simplest and most convenient solution: func name(v interface{}) { switch x := v.(type) { case []MyInterface: fmt.Println("[]MyInterface, len:", len(x)) for