mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
36 lines
832 B
Go
36 lines
832 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
type Skipper func(*http.Request) bool
|
|
|
|
// RequestURIWhitelistSkipper returns a HTTPMiddlewareConfig.Skipper which skips all but the given uris
|
|
func RequestURIWhitelistSkipper(uris ...string) Skipper {
|
|
urisMap := make(map[string]bool, len(uris))
|
|
for _, uri := range uris {
|
|
urisMap[uri] = true
|
|
}
|
|
return func(r *http.Request) bool {
|
|
if _, ok := urisMap[r.RequestURI]; ok {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
|
|
// RequestURIBlacklistSkipper returns a HTTPMiddlewareConfig.Skipper which skips the given uris
|
|
func RequestURIBlacklistSkipper(uris ...string) Skipper {
|
|
urisMap := make(map[string]bool, len(uris))
|
|
for _, uri := range uris {
|
|
urisMap[uri] = true
|
|
}
|
|
return func(r *http.Request) bool {
|
|
if _, ok := urisMap[r.RequestURI]; ok {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
}
|