diff --git a/guard.go b/guard.go index cfab627..f3fa9d2 100644 --- a/guard.go +++ b/guard.go @@ -18,6 +18,7 @@ type Guard struct { AllowIPNet *net.IPNet `json:"allow_ipnet"` basicAuth string + Skip func(r *http.Request) bool } func New() *Guard { @@ -91,6 +92,9 @@ func (g *Guard) Guard(next http.Handler) http.Handler { } else { cl = l.Info() } + if g.Skip != nil && g.Skip(r) { + return + } cl. Str("method", r.Method). Str("ip", ip). diff --git a/guard_test.go b/guard_test.go index fe27835..9720947 100644 --- a/guard_test.go +++ b/guard_test.go @@ -28,5 +28,9 @@ func TestGuard(t *testing.T) { mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { rw.Write([]byte("ok")) }) - http.ListenAndServe(":8000", New().Guard(mux)) + g := New() + g.Skip = func(r *http.Request) bool { + return r.URL.Path == "/skip" + } + http.ListenAndServe(":8000", g.Guard(mux)) }