From 2efe298c755a117af44a001e0f0a9d3d4aeedb99 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Sat, 30 Jul 2011 19:41:50 +0100 Subject: [PATCH] Make IRCHandler the function type, make NewHandler the factory. --- client/handlers.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/client/handlers.go b/client/handlers.go index f0a582e..249a15e 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -8,25 +8,23 @@ import ( "strings" ) +// An IRC handler looks like this: +type IRCHandler func(*Conn, *Line) + // AddHandler() adds an event handler for a specific IRC command. // -// Handlers take the form of an anonymous function (currently): -// func(conn *irc.Conn, line *irc.Line) { -// // handler code here -// } -// // Handlers are triggered on incoming Lines from the server, with the handler // "name" being equivalent to Line.Cmd. Read the RFCs for details on what // replies could come from the server. They'll generally be things like // "PRIVMSG", "JOIN", etc. but all the numeric replies are left as ascii // strings of digits like "332" (mainly because I really didn't feel like // putting massive constant tables in). -func (conn *Conn) AddHandler(name string, f func(*Conn, *Line)) { - conn.Registry.AddHandler(name, IRCHandler(f)) +func (conn *Conn) AddHandler(name string, f IRCHandler) { + conn.Registry.AddHandler(name, NewHandler(f)) } // Wrap f in an anonymous unboxing function -func IRCHandler(f func(*Conn, *Line)) event.Handler { +func NewHandler(f IRCHandler) event.Handler { return event.NewHandler(func(ev ...interface{}) { f(ev[0].(*Conn), ev[1].(*Line)) })