I am super confused about this, I have:
func getKind(v interface{}) string {
rt := reflect.TypeOf(v)
switch rt.Kind() {
case reflect.Slice:
return "slice"
case reflect.Array:
return "array"
default:
return "unknown"
}
}
func FlattenDeep(args ...interface{}) []interface{} {
list := []interface{}{}
for _, v := range args {
kind := getKind(v)
if kind != "unknown" {
for _, z := range FlattenDeep((v.([]interface{}))...) { // FAILS HERE
list = append(list, z)
}
} else {
list = append(list, v);
}
}
return list;
}
the error is:
panic: interface conversion: interface {} is []func(http.HandlerFunc) http.HandlerFunc, not []interface {}
I don't understand, I thought a slice of anything could be converted to a slice of interface{}
I think I fixed the runtime error by doing this:
for _, v := range args {
kind := getKind(v)
if kind != "unknown" {
a, ok := v.([]interface{})
if ok == false {
panic("o fuk")
}
for _, z := range FlattenDeep(a...) {
list = append(list, z)
}
} else {
list = append(list, v);
}
}
still feels wrong tho, why Go? why