Skip to content

Instantly share code, notes, and snippets.

@soul9
Created October 9, 2010 11:52
Show Gist options
  • Save soul9/618127 to your computer and use it in GitHub Desktop.
Save soul9/618127 to your computer and use it in GitHub Desktop.
diff --git a/irc_callback.go b/irc_callback.go
index 10ff827..f8d3768 100644
--- a/irc_callback.go
+++ b/irc_callback.go
@@ -11,11 +11,9 @@ import (
func (irc *IRCConnection) AddCallback(eventcode string, callback func(*IRCEvent)) {
eventcode = strings.ToUpper(eventcode)
if event, ok := irc.events[eventcode]; ok {
- // TODO: Grow this dynamically
- event = event[0 : len(event)+1]
- event[len(event)-1] = callback
+ event[len(event)] = callback
} else {
- event = make([]func(*IRCEvent), 1, 20)
+ event = make(map[int]func(*IRCEvent))
event[0] = callback
irc.events[eventcode] = event
}
@@ -24,9 +22,9 @@ func (irc *IRCConnection) AddCallback(eventcode string, callback func(*IRCEvent)
func (irc *IRCConnection) ReplaceCallback(eventcode string, i uint8, callback func(*IRCEvent)) {
eventcode = strings.ToUpper(eventcode)
if event, ok := irc.events[eventcode]; ok {
- event[i] = callback
+ event[int(i)] = callback
} else {
- event = make([]func(*IRCEvent), 1, 20)
+ event = make(map[int]func(*IRCEvent))
event[0] = callback
irc.events[eventcode] = event
}
@@ -55,12 +53,12 @@ func (irc *IRCConnection) RunCallbacks(event *IRCEvent) {
go callback(event)
}
} else {
- fmt.Printf("No callback for: %#v\n", event)
- }
+ fmt.Printf("No callback for: %#v\n", event)
+ }
}
func (irc *IRCConnection) setupCallbacks() {
- irc.events = make(map[string][]func(*IRCEvent))
+ irc.events = make(map[string]map[int]func(*IRCEvent))
//Handle ping events
irc.AddCallback("PING", func(e *IRCEvent) { irc.SendRaw("PONG :" + e.Message) })
diff --git a/irc_struct.go b/irc_struct.go
index e0b9a07..bab5455 100644
--- a/irc_struct.go
+++ b/irc_struct.go
@@ -19,7 +19,7 @@ type IRCConnection struct {
registered bool
server string
Password string
- events map[string][]func(*IRCEvent)
+ events map[string]map[int]func(*IRCEvent)
lastMessage int64
ticker <-chan int64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment