A small dispatcher framework for Go.
Go get it with
go get github.com/TimSatke/events
First, define your custom events.
const (
EventExample uint16 = iota
EventGreeting
EventGoodbye
)
Second, create a dispatcher.
disp := events.NewDispatcher()
disp.RegisterFunc(EventGreeting, func(evt events.Event) {
// evt.Type == EventGreeting
fmt.Printf("Hello, %v!\n", evt.Data)
})
Third, fire an event.
evtGreeting := events.Event{
Type: EventGreeting,
Data: "World",
}
disp.Fire(evtGreeting)
Have a look at the examples.