How can I create []string from struct's values in Go? For example, in the following struct:
type Person struct {
Height float64
Weight float64
Name string
Born string
}
Tim := Person{174.5, 68.3, "Tim", "United States"}
What I want to get is the following one:
[]string{"174.5", "68.3", "Tim", "United States"}
Since I want to save each record which is derived from the struct to a CSV file, and Write method of the *csv.Writer requires to take the data as []string, I have to convert such struct to []string.
Of course I can define a method on the struct and have it return []string, but I'd like to know a way to avoid calling every field (i.e. person.Height, person.Weight, person.Name...) since the actual data includes much more field.
Thanks.