Last active
August 29, 2015 14:02
-
-
Save doug/682fa24001e3e8f2ff5f to your computer and use it in GitHub Desktop.
Compose converts middleware func(http.ResponseWriter, http.Response, http.HandlerFunc) to func(http.Handler)http.Handler | Negroni to Alice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Middleware interface { | |
ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) | |
} | |
func Compose(m Middleware) func(http.Handler) http.Handler { | |
return func(next http.Handler) http.Handler { | |
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | |
m.ServeHTTP(rw, r, next.ServeHTTP) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment