Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make middleware mountable on http.NewMuxer() #3415

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion http/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ type (
)

// NewMuxer returns a Muxer implementation based on a Chi router.
func NewMuxer() ResolverMuxer {
// The middlewares will be mounted at the top level of the router.
func NewMuxer(middlewares ...func(http.Handler) http.Handler) ResolverMuxer {
r := chi.NewRouter()
for _, middleware := range middlewares {
r.Use(middleware)
}
r.NotFound(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ctx := context.WithValue(req.Context(), AcceptTypeKey, req.Header.Get("Accept"))
enc := ResponseEncoder(ctx, w)
Expand Down