I am attempting to write a simple recursive function to traverse a structure in Go and look for a certain type however I am having a hard time dealing with a structure in a map and reflection
The example below illustrates the issue
https://play.golang.org/p/GcInr8CoVe8
I cannot call v.MapIndex(key)
because I get an issue that it is not a pointer and I cannot address it either.
How do I deal with that?
Also when looking for a struct type by comparing v.Type, how do I make sure that I found the type regardless of whether it is a pointer or not (As I might want to call a function on it)? My code above compares to reflect.TypeOf(Second{})
but I would also like to cover a pointer of Second. Would adding the check for reflect.TypeOf(&Second{})
suffice?
Aucun commentaire:
Enregistrer un commentaire