I have a map which has a struct as value, as below:
type Record struct {
ID int
Type string
Year string
}
m := make(map[int]Record)
Once I populate this map with some records, I'm trying to export them as a csv with:
file, err := os.Create("export.csv")
checkError("Error:", err)
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
for key, value := range m {
r := make([]string, 0, 1+len(value))
r = append(r, key)
r = append(r, value)
}
writer.Flush()
I'm getting the error invalid argument value (type Record) for len
. How should I handle the struct here to? Do I have to convert it to string somehow?