I'm trying to append to a slice within a map:
type MyOuterStruct struct{
name string
inners map[string]MyInnerStruct
}
type MyInnerStruct struct{
name string
list []int
}
func main() {
ms := MyOuterStruct{
name: "outer",
inners: map[string]MyInnerStruct{
"a": {name: "inner"},
},
}
ms.inners["a"].list = append(ms.inners["a"].list, 4, 5, 6)
fmt.Println(ms.inners["a"].list)
//cannot assign to struct field ms.inners["a"].list in map
}
I know the issue is I'm assigning to an "unaddressable" field, but I'm not sure how to structure this properly.
I've tried the following
myCurrentList := ms.inners["a"].list
myCurrentList = append(myCurrentList, 4, 5, 6)
ms.inners["a"].list = myCurrentList
But this wasn't correct either.
How should I structure the MyInnerStruct
so that I can have access to a dynamic slice list
than I can append to?