Documentation ¶
Index ¶
- Variables
- func BatchLoad(l *List, entries []string) error
- func BatchLoadFromFiles(l *List, files []string) error
- func Load(l *List, entry string) error
- func LoadFromDAT(l *List, file, tag string) error
- func LoadFromFile(l *List, file string) error
- func LoadFromReader(l *List, reader io.Reader) error
- func LoadFromText(l *List, s string) error
- func LoadFromTextFile(l *List, file string) error
- func ParseIP(s string) (IPv6, IPVersion, error)
- type IPVersion
- type IPv6
- type List
- func (list *List) Append(newNet ...Net)
- func (list *List) Contains(ipv6 IPv6) (bool, error)
- func (list *List) Len() int
- func (list *List) Less(i, j int) bool
- func (list *List) Match(ip net.IP) (bool, error)
- func (list *List) Merge(srcList *List)
- func (list *List) Sort()
- func (list *List) Swap(i, j int)
- type Matcher
- type Net
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidIP = errors.New("invalid ip")
)
var ErrNotSorted = errors.New("list is not sorted")
var LoadFromDATFunc func(l *List, file, tag string) error
Functions ¶
func BatchLoad ¶
BatchLoad is a helper func to load multiple files using Load. It might modify the List and causes List unsorted.
func BatchLoadFromFiles ¶
func Load ¶
Load loads data from entry. If entry begin with "ext:", Load loads the file by using LoadFromFile. Else it loads the entry as a text pattern by using LoadFromText.
func LoadFromDAT ¶
func LoadFromFile ¶
LoadFromFile loads ip from a text file or a geoip file. If file contains a ':' and has format like 'geoip:cn', it will be read as a geoip file. It might modify the List and causes List unsorted.
func LoadFromReader ¶
LoadFromReader loads IP list from a reader. It might modify the List and causes List unsorted.
func LoadFromText ¶
LoadFromText loads an IP from s. It might modify the List and causes List unsorted.
func LoadFromTextFile ¶
LoadFromTextFile reads IP list from a text file. It might modify the List and causes List unsorted.
Types ¶
type IPv6 ¶
type IPv6 [2]uint64
IPv6 represents a ipv6 addr
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of Net. It stores all Net in one single slice and use binary search. It is suitable for large static cidr search.
func NewListFrom ¶ added in v3.1.0
NewListFrom returns a *List using l as its initial contents. The new List takes ownership of l, and the caller should not use l after this call.
func (*List) Append ¶
Append appends new Nets to the list. This modified the list. Caller must call List.Sort() before calling List.Contains()
func (*List) Merge ¶
Merge merges srcList with list This modified the list. Caller must call List.Sort() before calling List.Contains()
type Net ¶
type Net struct {
// contains filtered or unexported fields
}
Net represents an ip network
func NewNet ¶
NewNet returns a new IPNet, mask should be an ipv6 mask, which means you should +96 if you have an ipv4 mask.
func ParseCIDR ¶
ParseCIDR parses s as a CIDR notation IP address and prefix length. As defined in RFC 4632 and RFC 4291.