-
Notifications
You must be signed in to change notification settings - Fork 32
/
handler.go
40 lines (31 loc) · 867 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package godo
// Handler is the interface which all task handlers eventually implement.
type Handler interface {
Handle(*Context) error
}
// HandlerFunc is Handler adapter.
type HandlerFunc func() error
// Handle implements Handler.
func (f HandlerFunc) Handle(*Context) error {
return f()
}
// VoidHandlerFunc is a Handler adapter.
type VoidHandlerFunc func()
// Handle implements Handler.
func (v VoidHandlerFunc) Handle(*Context) error {
v()
return nil
}
// ContextHandlerFunc is a Handler adapter.
type ContextHandlerFunc func(*Context) error
// Handle implements Handler.
func (c ContextHandlerFunc) Handle(ctx *Context) error {
return c(ctx)
}
// VoidContextHandlerFunc is a Handler adapter.
type VoidContextHandlerFunc func(*Context)
// Handle implements Handler.
func (f VoidContextHandlerFunc) Handle(ctx *Context) error {
f(ctx)
return nil
}