MCPcopy
hub / github.com/gorilla/mux / Middleware

Method Middleware

example_authentication_middleware_test.go:24–36  ·  view source on GitHub ↗

Middleware function, which will be called for each request

(next http.Handler)

Source from the content-addressed store, hash-verified

22
23// Middleware function, which will be called for each request
24func (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
38func Example_authenticationMiddleware() {
39 r := mux.NewRouter()

Callers

nothing calls this directly

Calls 3

HandlerFuncMethod · 0.80
GetMethod · 0.80
ServeHTTPMethod · 0.45

Tested by

no test coverage detected