mirror of
https://github.com/adnanh/webhook.git
synced 2026-07-27 09:39:15 +08:00
Update GH actions and dependencies (#681)
* Update go-chi dependency to v5 * Update gofrs/uuid dependency to v5 * Update gorilla/mux dependency to v1.8.1 * Update go-humanize dependency to v1.0.1 * Update mxj dependency to v2.7.0 * Update fsnotify dependency to v1.7.0 * Update Go versions in GH build workflow * Update gopkg.in/yaml.v2 indirect dependency to v2.4.0 * Bump GH actions
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// SupressNotFound will quickly respond with a 404 if the route is not found
|
||||
// and will not continue to the next middleware handler.
|
||||
//
|
||||
// This is handy to put at the top of your middleware stack to avoid unnecessary
|
||||
// processing of requests that are not going to match any routes anyway. For
|
||||
// example its super annoying to see a bunch of 404's in your logs from bots.
|
||||
func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
rctx := chi.RouteContext(r.Context())
|
||||
match := rctx.Routes.Match(rctx, r.Method, r.URL.Path)
|
||||
if !match {
|
||||
router.NotFoundHandler().ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user