iprangetree

package module
v0.0.0-...-fa4f5db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2018 License: MIT Imports: 4 Imported by: 0

README

iprangetree

Simple IP range tree collection

tree := iprangetree.New(2)

if item, err := iprangetree.ItemByString("86.100.32.0-86.100.32.255"); nil == err {
  tree.Add(item)
} else {
  log.Fatal(err)
}

fmt.Println(tree.Lookup(net.ParseIP("86.100.32.10")))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidItem = errors.New("iprangetree: invalid IP range item")

ErrInvalidItem message

View Source
var ErrInvalidItemParse = errors.New("Invalid parse item")

ErrInvalidItemParse by string

Functions

This section is empty.

Types

type IP

type IP net.IP

IP implementation btree campare

func (IP) Less

func (ip IP) Less(then btree.Item) bool

Less camparing for btree

type IPItem

type IPItem struct {
	StartIP net.IP
	EndIP   net.IP
	Data    interface{}
}

IPItem IP range

func ItemByString

func ItemByString(s string) (item *IPItem, err error)

ItemByString parse

func (*IPItem) Compare

func (i *IPItem) Compare(it interface{}) int

Compare with the second item

func (*IPItem) Has

func (i *IPItem) Has(ip net.IP) bool

Has IP in range

func (*IPItem) Less

func (i *IPItem) Less(then btree.Item) bool

Less camparing for btree

func (*IPItem) Normalize

func (i *IPItem) Normalize()

Normalize IP values

type IPTree

type IPTree struct {
	// contains filtered or unexported fields
}

IPTree base

func New

func New(degree int) *IPTree

New tree object

func (*IPTree) Add

func (t *IPTree) Add(item *IPItem) error

Add IP range item

func (*IPTree) AddRange

func (t *IPTree) AddRange(ip1, ip2 net.IP, val interface{}) error

AddRange IPs vith value

func (*IPTree) Lookup

func (t *IPTree) Lookup(ip net.IP) (response *IPItem)

Lookup item by IP

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL