I am trying to add data to the map without prior assignment, if I had the usual map[string][]string variable map[string][]string I could do it like this -> make(map[string][]string) , but I have type -> type Header map[string][]string .

Here is the code:

 func (h Header) Add(key, value string) error { h[key] = append(h[key], value) } 

Knocks out: panic: assignment to entry in nil map . How can I solve this problem?

  • 2
    With type, you express the security properties of working with types. But your Header is still inside map [string] [] string. Accordingly, of course, before accessing it, you need to initialize the map. For example, using the same make (map [string] [] string). play.golang.org/p/JgX5WK6ClEl - Fulcrum

0