I am trying to create a struct, one of whose fields is a map. However, I cannot initialize it with a method and then insert a value with another method. It reports error
panic: assignment to entry in nil map
Coming from a Python background, I am confused on what I missed.
Here is the goal playground snippet
package main
type profile map[string]float64
type foobar struct {
foo profile
bar map[string]profile
}
func (fb foobar) Init() {
fb.foo = make(profile)
fb.bar = make(map[string]profile)
}
func (fb foobar) Set() {
fb.bar["foo1"] = make(profile)
}
func main() {
test := foobar{}
test.Init()
test.Set()
}