parent
6793e8ef1d
commit
e27c6e7f45
4
guard.go
4
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).
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue