Skip to content

Commit ec5a525

Browse files
committed
perf: short circuit custom error handler loading if no custom error handlers have been registered
1 parent af31c9a commit ec5a525

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

router.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ func NewRouter() *Router {
3232
// We also intercept any error handlers returned by the underlying mux, and replace them with any
3333
// custom error handlers that have been registered.
3434
func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
35-
handler, pattern := rt.Mux.Handler(r)
35+
if len(rt.errorHandlers) == 0 {
36+
rt.Mux.ServeHTTP(w, r)
37+
return
38+
}
3639

40+
handler, pattern := rt.Mux.Handler(r)
3741
if pattern == "" && handler != nil {
3842
// If pattern is empty, we have an internal error handler. Check to see if we have a custom
3943
// error handler for this error code, and use that if we do.
@@ -44,7 +48,6 @@ func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4448
handler = h
4549
}
4650
}
47-
4851
handler.ServeHTTP(w, r)
4952
}
5053

0 commit comments

Comments
 (0)