Original post

Hello fellow Gophers! I’m still learning the ins & outs of Lang and wanted to ask about the best way to extract data from a struct containing an array of another struct.

For example if we have a struct called “People” that defines another struct “Person” as an array. Let’s say “Person” has string definitions of “name”, “phone”, “email”.

My goal in this scenario is to create a function that consumes an input of “People” which then outputs a separate function call for every “Person” using the “email” field as input.

My first thought to accomplish this is iteration, basically loop through the array and extract the specific field but I’ve also heard about reflection as an option.

The question for my wonderfully opinionated community is what patterns are preferable in Go Lang too accomplish this task?