Blame view
middleware.go
958 Bytes
ad8e9dd2a added middleware ... |
1 2 3 4 |
package webutility import ( "net/http" |
ad8e9dd2a added middleware ... |
5 |
) |
3fffcb954 removed old http API |
6 |
func SetHeaders(h http.HandlerFunc) http.HandlerFunc { |
0a60d9a1c switched from han... |
7 |
return func(w http.ResponseWriter, req *http.Request) { |
ad8e9dd2a added middleware ... |
8 9 10 11 |
SetDefaultHeaders(w) if req.Method == http.MethodOptions { return } |
0a60d9a1c switched from han... |
12 13 |
h(w, req) } |
ad8e9dd2a added middleware ... |
14 |
} |
3fffcb954 removed old http API |
15 |
func ParseForm(h http.HandlerFunc) http.HandlerFunc { |
0a60d9a1c switched from han... |
16 |
return func(w http.ResponseWriter, req *http.Request) { |
ad8e9dd2a added middleware ... |
17 18 19 20 21 |
err := req.ParseForm() if err != nil { BadRequest(w, req, err.Error()) return } |
0a60d9a1c switched from han... |
22 23 |
h(w, req) } |
ad8e9dd2a added middleware ... |
24 |
} |
3f8e3c437 minor changes |
25 26 27 28 29 30 31 32 33 34 |
func ParseMultipartForm(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { err := req.ParseMultipartForm(32 << 20) if err != nil { BadRequest(w, req, err.Error()) return } h(w, req) } } |
3fffcb954 removed old http API |
35 |
func Auth(roles string, h http.HandlerFunc) http.HandlerFunc { |
0a60d9a1c switched from han... |
36 |
return func(w http.ResponseWriter, req *http.Request) { |
3f8e3c437 minor changes |
37 38 |
if _, err := AuthCheck(req, roles); err != nil { Unauthorized(w, req, err.Error()) |
ad8e9dd2a added middleware ... |
39 40 |
return } |
0a60d9a1c switched from han... |
41 42 |
h(w, req) } |
ad8e9dd2a added middleware ... |
43 |
} |