How to read struct field names from an empty slice of structs

Visto 218 veces
Saltar al primer mensaje no leído

Mark

no leída,
21 nov 2022, 5:55:0621/11/22
a golang-nuts
I have a two level general-purpose data structure: a struct containing one or more slices of structs.
I want to be able to use reflection to populate this, but as a first step I want to extract the
"table names" (i.e., the names of the fields of the outer struct), and the "field names" (the names of each field in each of the inner structs).
Below is as far as I've got: it correctly finds the table names (including their tag alternatives), but I can't work out how to access the field names...

playground

Mark

no leída,
21 nov 2022, 6:19:4721/11/22
a golang-nuts
After struggling, I finally solved it; playground
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos