forked from QLeelulu/goku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
55 lines (50 loc) · 1.45 KB
/
filter.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 goku
// Order of the filters execution is:
// 1. OnActionExecuting
// 2. -> Execute Action -> return ActionResulter
// 3. OnActionExecuted
// 4. OnResultExecuting
// 5. -> ActionResulter.ExecuteResult
// 6. OnResultExecuted
type Filter interface {
OnActionExecuting(ctx *HttpContext) (ActionResulter, error)
OnActionExecuted(ctx *HttpContext) (ActionResulter, error)
OnResultExecuting(ctx *HttpContext) (ActionResulter, error)
OnResultExecuted(ctx *HttpContext) (ActionResulter, error)
}
func runFilterActionExecuting(ctx *HttpContext, filters []Filter) (ar ActionResulter, err error) {
for _, f := range filters {
ar, err = f.OnActionExecuting(ctx)
if ctx.Canceled || ar != nil || err != nil {
return
}
}
return
}
func runFilterActionExecuted(ctx *HttpContext, filters []Filter) (ar ActionResulter, err error) {
for _, f := range filters {
ar, err = f.OnActionExecuted(ctx)
if ctx.Canceled || ar != nil || err != nil {
return
}
}
return
}
func runFilterResultExecuting(ctx *HttpContext, filters []Filter) (ar ActionResulter, err error) {
for _, f := range filters {
ar, err = f.OnResultExecuting(ctx)
if ctx.Canceled || ar != nil || err != nil {
return
}
}
return
}
func runFilterResultExecuted(ctx *HttpContext, filters []Filter) (ar ActionResulter, err error) {
for _, f := range filters {
ar, err = f.OnResultExecuted(ctx)
if ctx.Canceled || ar != nil || err != nil {
return
}
}
return
}