Commit 0a60d9a1c07d143118e3d494090bfbbed1342b48
1 parent
ad8e9dd2af
Exists in
master
and in
1 other branch
switched from handler to handlerfuncs
Showing
1 changed file
with
16 additions
and
16 deletions
Show diff stats
middleware.go
... | ... | @@ -5,43 +5,43 @@ import ( |
5 | 5 | "time" |
6 | 6 | ) |
7 | 7 | |
8 | -func WithSetHeaders(h http.Handler) http.Handler { | |
9 | - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | |
8 | +func WithSetHeaders(h http.HandlerFunc) http.HandlerFunc { | |
9 | + return func(w http.ResponseWriter, req *http.Request) { | |
10 | 10 | SetDefaultHeaders(w) |
11 | 11 | if req.Method == http.MethodOptions { |
12 | 12 | return |
13 | 13 | } |
14 | - h.ServeHTTP(w, req) | |
15 | - }) | |
14 | + h(w, req) | |
15 | + } | |
16 | 16 | } |
17 | 17 | |
18 | -func WithParseForm(h http.Handler) http.Handler { | |
19 | - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | |
18 | +func WithParseForm(h http.HandlerFunc) http.HandlerFunc { | |
19 | + return func(w http.ResponseWriter, req *http.Request) { | |
20 | 20 | err := req.ParseForm() |
21 | 21 | if err != nil { |
22 | 22 | BadRequest(w, req, err.Error()) |
23 | 23 | return |
24 | 24 | } |
25 | - h.ServeHTTP(w, req) | |
26 | - }) | |
25 | + h(w, req) | |
26 | + } | |
27 | 27 | } |
28 | 28 | |
29 | -func WithLog(h http.Handler) http.Handler { | |
30 | - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | |
29 | +func WithLog(h http.HandlerFunc) http.HandlerFunc { | |
30 | + return func(w http.ResponseWriter, req *http.Request) { | |
31 | 31 | reqLogger.LogRequest(req, "") |
32 | 32 | t1 := time.Now() |
33 | - h.ServeHTTP(w, req) | |
33 | + h(w, req) | |
34 | 34 | t2 := time.Now() |
35 | 35 | reqLogger.LogResponse(w, t2.Sub(t1)) |
36 | - }) | |
36 | + } | |
37 | 37 | } |
38 | 38 | |
39 | -func WithAuth(h http.Handler, authorizedRoles []string) http.Handler { | |
40 | - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | |
39 | +func WithAuth(h http.HandlerFunc, authorizedRoles []string) http.HandlerFunc { | |
40 | + return func(w http.ResponseWriter, req *http.Request) { | |
41 | 41 | if _, ok := AuthCheck(req, authorizedRoles); !ok { |
42 | 42 | Unauthorized(w, req, "") |
43 | 43 | return |
44 | 44 | } |
45 | - h.ServeHTTP(w, req) | |
46 | - }) | |
45 | + h(w, req) | |
46 | + } | |
47 | 47 | } | ... | ... |