netalloc

package module
v0.0.0-...-23a3be6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: BSD-3-Clause Imports: 4 Imported by: 2

README

netalloc - a small IP allocator library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrefixFull = errors.New("no more ip addresses available in prefix")
)

Functions

func CIDR

func CIDR(prefix *net.IPNet, ip *net.IPAddr) string

Types

type Allocator

type Allocator interface {
	Alloc() (*net.IPAddr, error)
	AllocCIDR() (cidr string, err error)
	Free(*net.IPAddr) error
	FreeCIDR(cidr string) error
	SetStore(store Store)
	CIDR(*net.IPAddr) string
}

func NewGenericAlloc

func NewGenericAlloc(store Store, prefix string) (Allocator, error)

func NewMemAlloc

func NewMemAlloc(prefix string) (Allocator, error)

type GenericAlloc

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

func (*GenericAlloc) Alloc

func (a *GenericAlloc) Alloc() (ip *net.IPAddr, err error)

func (*GenericAlloc) AllocCIDR

func (a *GenericAlloc) AllocCIDR() (cidr string, err error)

func (*GenericAlloc) CIDR

func (a *GenericAlloc) CIDR(ip *net.IPAddr) string

func (*GenericAlloc) Free

func (a *GenericAlloc) Free(ip *net.IPAddr) (err error)

func (*GenericAlloc) FreeCIDR

func (a *GenericAlloc) FreeCIDR(cidr string) (err error)

func (*GenericAlloc) SetStore

func (a *GenericAlloc) SetStore(store Store)

type MemStore

type MemStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*MemStore) Add

func (m *MemStore) Add(key string) error

func (*MemStore) Delete

func (m *MemStore) Delete(key string) error

func (*MemStore) Exists

func (m *MemStore) Exists(key string) (bool, error)

type Store

type Store interface {
	sync.Locker
	Exists(key string) (bool, error)
	Add(key string) error
	Delete(key string) error
}

func NewMemStore

func NewMemStore() Store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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