So I have a struct like this:
type Magni struct {
...
Handlers map[string]func(*Message)
...
}
And I have a function to create a new instance of the struct:
func New(nick, user, real string) *Magni {
return &Magni{
...
Handlers: make(map[string]func(*Message)),
...
}
}
But I can't get something from the Handlers
map with the key "hey"
when "hey"
is in a variable, it only works if I type it myself. Here is a method of the struct Magni
and m
is a pointer to the struct Magni
:
handler := m.Handlers[cmd[3][1:]] // cmd[3][1:] contains string "hey"
handler2 := m.Handlers["hey"]
For some reason, the value of handler
is nil
and the value of handler2
is 0x401310
, basically I am not expecting handler
to be nil
.
Am I doing something wrong or is this the expected behavior?