diff --git a/middleware/clean_path.go b/middleware/clean_path.go index adeba429..d77476ab 100644 --- a/middleware/clean_path.go +++ b/middleware/clean_path.go @@ -12,17 +12,19 @@ import ( func CleanPath(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rctx := chi.RouteContext(r.Context()) - - routePath := rctx.RoutePath + + var routePath string + if rctx != nil { + routePath = rctx.RoutePath + } if routePath == "" { if r.URL.RawPath != "" { routePath = r.URL.RawPath } else { routePath = r.URL.Path } - rctx.RoutePath = path.Clean(routePath) } - + rctx.RoutePath = path.Clean(routePath) next.ServeHTTP(w, r) }) }