vendredi 23 février 2018

How to use reflect to recursively parse nested struct in Go?

I have a nested three layer struct. I would like to use reflect in Go to parse it (use recursive function). The reasons to use reflect and the recursive function are

  • can have various number of fields (but the first two fields are fixed)
  • the field types are not fixed.
  • The number of nested layers can be different (in this example only three layers. It can be many more)

Here are some codes. enter image description here

When I ran this, in the first layer I got "type: *entity.SacWebIS". However, in the second iteration/recursion, I got "type: *reflect.rtype" .

How to modify this code? Thanks.





Aucun commentaire:

Enregistrer un commentaire