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

376 views
Skip to first unread message

Mark

unread,
Nov 21, 2022, 5:55:06 AM11/21/22
to 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

unread,
Nov 21, 2022, 6:19:47 AM11/21/22
to golang-nuts
After struggling, I finally solved it; playground
Reply all
Reply to author
Forward
0 new messages