I'm trying to create a slice of Maps. Although the code compiles fine, I get the runtime error below:
mapassign1: runtime·panicstring("assignment to entry in nil map");
I attempt to make an array of Maps, with each Map containing two indicies, a "Id" and a "Investor". My code looks like this:
for _, row := range rows {
var inv_ids []string
var inv_names []string
//create arrays of data from MySQLs GROUP_CONCAT function
inv_ids = strings.Split(row.Str(10), ",")
inv_names = strings.Split(row.Str(11), ",")
length := len(inv_ids);
invs := make([]map[string]string, length)
//build map of ids => names
for i := 0; i < length; i++ {
invs[i] = make(map[string]string)
invs[i]["Id"] = inv_ids[i]
invs[i]["Investor"] = inv_names[i]
}//for
//build Message and return
msg := InfoMessage{row.Int(0), row.Int(1), row.Str(2), row.Int(3), row.Str(4), row.Float(5), row.Float(6), row.Str(7), row.Str(8), row.Int(9), invs}
return(msg)
} //for
I initially thought something like below would work, however that did not fix the issue either. Any ideas?
invs := make([]make(map[string]string), length)