-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
40 lines (29 loc) · 762 Bytes
/
handler.go
File metadata and controls
40 lines (29 loc) · 762 Bytes
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 mohttp
import (
"golang.org/x/net/context"
)
type Handler interface {
Handle(context.Context)
}
type HandlerFunc func(context.Context)
func (h HandlerFunc) Handle(c context.Context) {
h(c)
}
type PriorityHandler interface {
Priority() int
Handler
}
type priorityHandler struct {
priority int
handler Handler
}
func (p *priorityHandler) Priority() int { return p.priority }
func (p *priorityHandler) Handle(c context.Context) { p.handler.Handle(c) }
func PriorityHandlerFunc(p int, fn HandlerFunc) PriorityHandler {
return &priorityHandler{p, fn}
}
var EmptyBodyHandler Handler = HandlerFunc(func(c context.Context) {})
type ChainedHandlers []Handler
func (ch ChainedHandlers) Handle(c context.Context) {
Serve(c, ch...)
}