From 3feaa7f30219930cedeff235447b4313071962cb Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Mon, 7 Nov 2011 13:44:03 +0000 Subject: [PATCH] Use a static map of event handlers for internal handlers too. --- client/handlers.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/handlers.go b/client/handlers.go index f664941..078f228 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -33,12 +33,20 @@ func NewHandler(f IRCHandler) event.Handler { } // sets up the internal event handlers to do essential IRC protocol things +var intHandlers map[string]event.Handler +func init() { + intHandlers = make(map[string]event.Handler) + intHandlers["001"] = NewHandler((*Conn).h_001) + intHandlers["433"] = NewHandler((*Conn).h_433) + intHandlers["CTCP"] = NewHandler((*Conn).h_CTCP) + intHandlers["NICK"] = NewHandler((*Conn).h_NICK) + intHandlers["PING"] = NewHandler((*Conn).h_PING) +} + func (conn *Conn) addIntHandlers() { - conn.AddHandler("001", (*Conn).h_001) - conn.AddHandler("433", (*Conn).h_433) - conn.AddHandler("CTCP", (*Conn).h_CTCP) - conn.AddHandler("NICK", (*Conn).h_NICK) - conn.AddHandler("PING", (*Conn).h_PING) + for n, h := range intHandlers { + conn.ER.AddHandler(h, n) + } } // Basic ping/pong handler