I'm using reflect.ValueOf(..) to loop through elements in a struct. I noticed that calling NumField fails if i pass the struct vs. pointer to the struct in the ValueOf function.
v = reflect.ValueOf(user)
v.NumField() // panics
Vs.
v = reflect.ValueOf(*user)
v.NumField() // works
Is there a way to find out beforehand if v would panic, before calling NumField?
Aucun commentaire:
Enregistrer un commentaire