Documentation ¶
Overview ¶
Package ip filters HTTP traffic based on IP ranges. Supports IP v4/v6 and CIDR expressions. It also provides a middleware layer, useful for composition and multiplexing.
Index ¶
- Constants
- Variables
- type Filter
- func (f *Filter) Filter(fn ...FilterFunc)
- func (f *Filter) FilterHTTP(h http.Handler) func(w http.ResponseWriter, r *http.Request)
- func (f *Filter) Register(mw layer.Middleware)
- func (f *Filter) SetResponder(fn http.HandlerFunc)
- func (f *Filter) Use(handler interface{}) *Filter
- func (f *Filter) UseFinalHandler(handler http.Handler) *Filter
- func (f *Filter) UsePhase(phase string, handler interface{}) *Filter
- type FilterFunc
Constants ¶
const Version = "0.1.0"
Version defines the current package semantic version.
Variables ¶
var ForbiddenResponder = func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(403) w.Write([]byte("Forbidden: client IP not allowed")) }
ForbiddenResponder is used as default function to repond when the IP is not allowed. You can customize it via Filter.SetResponder(fn).
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter implements a IP range based authorization filter for incoming HTTP traffic.
func (*Filter) Filter ¶
func (f *Filter) Filter(fn ...FilterFunc)
Filter registers a new filter function. If the filter matches, the client IP won't be validated.
func (*Filter) FilterHTTP ¶
FilterHTTP filters an incoming HTTP request based on the client IP. If some filter passes, the request won't be limited.
func (*Filter) Register ¶
func (f *Filter) Register(mw layer.Middleware)
Register registers the middleware handler.
func (*Filter) SetResponder ¶
func (f *Filter) SetResponder(fn http.HandlerFunc)
SetResponder sets a custom function to reply in case that an IP not allowed.
func (*Filter) Use ¶
Use registers a new middleware handler in the middleware stack. The middleware will be executed only if the client IP is allowed.
func (*Filter) UseFinalHandler ¶
UseFinalHandler registers a new middleware handler in the middleware stack. The middleware will be executed only if the client IP is allowed.
type FilterFunc ¶
FilterFunc represents the filter function signature used to determine if should apply not the IP filtering.