Documentation ¶
Index ¶
- func IPToCountry(ipstr string) string
- func NetIPToCountry(ip net.IP) string
- func Wrap(next http.Handler, opts Options) http.Handler
- type IPFilter
- func (f *IPFilter) AllowCountry(code string)
- func (f *IPFilter) AllowIP(ip string) bool
- func (f *IPFilter) Allowed(ipstr string) bool
- func (f *IPFilter) BlockCountry(code string)
- func (f *IPFilter) BlockIP(ip string) bool
- func (f *IPFilter) Blocked(ip string) bool
- func (f *IPFilter) IPToCountry(ipstr string) string
- func (f *IPFilter) NetAllowed(ip net.IP) bool
- func (f *IPFilter) NetBlocked(ip net.IP) bool
- func (f *IPFilter) NetIPToCountry(ip net.IP) string
- func (f *IPFilter) ToggleCountry(code string, allowed bool)
- func (f *IPFilter) ToggleDefault(allowed bool)
- func (f *IPFilter) ToggleIP(str string, allowed bool) bool
- func (f *IPFilter) Wrap(next http.Handler) http.Handler
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPToCountry ¶
IPToCountry is a simple IP-country code lookup. Returns an empty string when cannot determine country.
func NetIPToCountry ¶
NetIPToCountry is a simple IP-country code lookup. Returns an empty string when cannot determine country.
Types ¶
type IPFilter ¶
type IPFilter struct {
// contains filtered or unexported fields
}
func (*IPFilter) AllowCountry ¶
func (*IPFilter) BlockCountry ¶
func (*IPFilter) IPToCountry ¶
func (*IPFilter) NetAllowed ¶
NetAllowed returns if a given net.IP can pass through the filter
func (*IPFilter) NetBlocked ¶
NetBlocked returns if a given net.IP can NOT pass through the filter
func (*IPFilter) ToggleCountry ¶
ToggleCountry alters a specific country setting
func (*IPFilter) ToggleDefault ¶
ToggleDefault alters the default setting
type Options ¶
type Options struct { //explicity allowed IPs AllowedIPs []string //explicity blocked IPs BlockedIPs []string //explicity allowed country ISO codes AllowedCountries []string //explicity blocked country ISO codes BlockedCountries []string //block by default (defaults to allow) BlockByDefault bool // TrustProxy enable check request IP from proxy TrustProxy bool // Logger enables logging, printing using the provided interface Logger interface { Printf(format string, v ...interface{}) } // These fields currently have no effect IPDB []byte IPDBPath string IPDBNoFetch bool IPDBFetchURL string }
Options for IPFilter. Allow supercedes Block for IP checks across all matching subnets, whereas country checks use the latest Allow/Block setting. IPs can be IPv4 or IPv6 and can optionally contain subnet masks (e.g. /24). Note however, determining if a given IP is included in a subnet requires a linear scan so is less performant than looking up single IPs.
This could be improved with cidr range prefix tree.