From 0a60d9a1c07d143118e3d494090bfbbed1342b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Thu, 3 May 2018 10:15:50 +0200 Subject: [PATCH] switched from handler to handlerfuncs --- middleware.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/middleware.go b/middleware.go index c56060b..2ea875c 100644 --- a/middleware.go +++ b/middleware.go @@ -5,43 +5,43 @@ import ( "time" ) -func WithSetHeaders(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { +func WithSetHeaders(h http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { SetDefaultHeaders(w) if req.Method == http.MethodOptions { return } - h.ServeHTTP(w, req) - }) + h(w, req) + } } -func WithParseForm(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { +func WithParseForm(h http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { err := req.ParseForm() if err != nil { BadRequest(w, req, err.Error()) return } - h.ServeHTTP(w, req) - }) + h(w, req) + } } -func WithLog(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { +func WithLog(h http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { reqLogger.LogRequest(req, "") t1 := time.Now() - h.ServeHTTP(w, req) + h(w, req) t2 := time.Now() reqLogger.LogResponse(w, t2.Sub(t1)) - }) + } } -func WithAuth(h http.Handler, authorizedRoles []string) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { +func WithAuth(h http.HandlerFunc, authorizedRoles []string) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { if _, ok := AuthCheck(req, authorizedRoles); !ok { Unauthorized(w, req, "") return } - h.ServeHTTP(w, req) - }) + h(w, req) + } } -- 1.8.1.2