Middleware function, which will be called for each request
(next http.Handler)
| 22 | |
| 23 | // Middleware function, which will be called for each request |
| 24 | func (amw *authenticationMiddleware) Middleware(next http.Handler) http.Handler { |
| 25 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 26 | token := r.Header.Get("X-Session-Token") |
| 27 | |
| 28 | if user, found := amw.tokenUsers[token]; found { |
| 29 | // We found the token in our map |
| 30 | log.Printf("Authenticated user %s\n", user) |
| 31 | next.ServeHTTP(w, r) |
| 32 | } else { |
| 33 | http.Error(w, "Forbidden", http.StatusForbidden) |
| 34 | } |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | func Example_authenticationMiddleware() { |
| 39 | r := mux.NewRouter() |
nothing calls this directly
no test coverage detected