Skip to content

Instantly share code, notes, and snippets.

@doug
Last active August 29, 2015 14:02
Show Gist options
  • Save doug/682fa24001e3e8f2ff5f to your computer and use it in GitHub Desktop.
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
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