mercredi 24 juin 2020

Golang concrete type from interface {} without knowing the type

If I have a variable that is interface{}, how do I actually get the values in a concrete type without any prior knowledge of the original structure of the interface{}?

For example lets say I have an interface{} that is really a []struct{abc string} and I don't know that its actually []struct{abc string}, how do I convert interface{} to []struct{abc string}? I don't mind using reflection.





Aucun commentaire:

Enregistrer un commentaire