-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
55 lines (40 loc) · 1.42 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package alox
import (
"net/http"
)
type Filter func(*http.Request) bool
type Handler func(Server, http.ResponseWriter, *http.Request)
type ErrorHandler func(Server, http.ResponseWriter, *http.Request, interface{})
type Middleware func(Handler) Handler
type ContextValues map[interface{}]interface{}
func (contextValues ContextValues) Get(key interface{}) interface{} {
return contextValues[key]
}
func (contextValues ContextValues) Set(key, value interface{}) {
contextValues[key] = value
}
func (contextValues ContextValues) Del(key interface{}) {
delete(contextValues, key)
}
type Server interface {
http.Handler
ResponseMethods
SetHandler(handler Handler) Server
ContextValues() ContextValues // map[interface{}]interface{}
// SetContextValue(key, value interface{})
// // Context returns the base context.Context.
// //
// // This context is propagated to all sub-servers and its
// Context() context.Context
// SetContext(context context.Context) Server
AddFilters(filters ...Filter) Server
AddMiddlewares(middlewares ...Middleware) Server
// Match checks whether incoming *http.Request should be handled
// by this server's handler.
//
// Match function will test request against all filters associated
// with this server. If the request doesn't pass any one of them,
// the Match function will return false. Otherwise, by default,
// the Match function will return true.
Match(request *http.Request) bool
}