forked from DanieleDaccurso/wrouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
50 lines (43 loc) · 1.54 KB
/
events.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
package wrouter
import (
"net/http"
"reflect"
)
// PreRequestEventContext contains the event context for events which are fired after the ServeHTTP method is called.
// At this point, nothing about the route and the further life-cycle of the request is known to the router yet.
// If values inside the context are manipulated, the manipulated version will be used in the further lifecycle of this
// request.
type PreRequestEventContext struct {
// Request contains the current request instance
Request *http.Request
// ResponseWriter contains the current ResponseWriter instance
ResponseWriter http.ResponseWriter
}
// PostRouteResolveEventContext contains the event context for events which are fired after the controller action has
// been called.
// If values inside the context are manipulated, the manipulated version will be used in the further lifecycle of this
// request.
type PostRequestEventContext struct {
Request *http.Request
ResponseWriter http.ResponseWriter
Values []reflect.Value
}
type PreRequestEvent interface {
Exec(*PreRequestEventContext)
}
type PostRequestEvent interface {
Exec(*PostRequestEventContext)
}
func createPreRequestEventContext(h *http.Request, w http.ResponseWriter) *PreRequestEventContext {
return &PreRequestEventContext{
Request: h,
ResponseWriter: w,
}
}
func createPostRequestEventContext(h *http.Request, w http.ResponseWriter, vs []reflect.Value) *PostRequestEventContext {
return &PostRequestEventContext{
Request: h,
ResponseWriter: w,
Values: vs,
}
}