go - How do you determine if a variable is a slice or array? -
I have a function that has been passed to the map, each of which should be controlled separately, its basis But that this type of a primitive or a piece piece is not known ahead of time. How can I determine which element are slices (or arrays) and which are not?
package. To play with you.
package main import "fmt" import "mirrored" func main () {m: = make (map [string] interface {}) I ["a"] = {] string {" A "," b "," c "} m [" b "] = [4] int {1, 2, 3, 4} test (m)} function test (m map [string] interface {}} { For V: = Range m {rt: = Reflect. (V) switch rt.kind () {Reflect matter. Slice: fmt.Println (k, "is a piece with element type", r. T.Elame ()) reflects the case: ARR: FMT. Printline (k, "element type Is the array with ", RT Eelam ()) default: fmt.Println (k," something else is completely ")}}}
Comments
Post a Comment