forked from savsgio/atreugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
43 lines (33 loc) · 812 Bytes
/
utils.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
package atreugo
import (
"reflect"
"github.com/valyala/fasthttp"
)
func viewToHandler(view View, errorView ErrorView) fasthttp.RequestHandler {
return func(ctx *fasthttp.RequestCtx) {
actx := AcquireRequestCtx(ctx)
if err := view(actx); err != nil {
errorView(actx, err, fasthttp.StatusInternalServerError)
}
ReleaseRequestCtx(actx)
}
}
func isEqual(v1, v2 interface{}) bool {
return reflect.ValueOf(v1).Pointer() == reflect.ValueOf(v2).Pointer()
}
func middlewaresInclude(ms []Middleware, fn Middleware) bool {
for _, m := range ms {
if isEqual(m, fn) {
return true
}
}
return false
}
func appendMiddlewares(dst, src []Middleware, skip ...Middleware) []Middleware {
for _, fn := range src {
if !middlewaresInclude(skip, fn) {
dst = append(dst, fn)
}
}
return dst
}