forked from belak/go-seabird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
26 lines (23 loc) · 1012 Bytes
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package seabird
// Handler is an interface representing objects which can be registered to serve
// a particular Event.Command or subcommand in the IRC client.
type Handler interface {
// HandleEvent should read the data, formulate a response action (if needed)
// and then return. Returning signals that the Handler is done with the
// current Event and will let the IRC client move on to the next Handler or
// Event.
//
// Note that if there are calls that may block for a long time such as
// network requests and IO, it may be best to grab the required data and run
// the response code in a goroutine so the rest of the Client can continue
// as usual.
HandleEvent(r *Request)
}
// The HandlerFunc is an adapter to allow the use of ordinary functions as IRC
// handlers. If f is a function with the appropriate signature, HandlerFunc(f)
// is a Handler object that calls f.
type HandlerFunc func(r *Request)
// HandleEvent calls f(c, e).
func (f HandlerFunc) HandleEvent(r *Request) {
f(r)
}