Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrFull = errors.New("range is full")
ErrNotInRange = errors.New("provided netid is not in the valid range")
ErrAllocated = errors.New("provided netid is already allocated")
)
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
func New ¶
func New(r *NetIDRange, allocatorFactory allocator.AllocatorFactory) *Allocator
New creates a Allocator over a netid Range, calling allocatorFactory to construct the backing store.
func NewInMemory ¶
func NewInMemory(r *NetIDRange) *Allocator
Helper that wraps New, for creating a range backed by an in-memory store.
func (*Allocator) Allocate ¶
func (r *Allocator) Allocate(id uint32) error
Allocate attempts to reserve the provided netid. ErrNotInRange or ErrAllocated will be returned if the netid is not valid for this range or has already been reserved.
func (*Allocator) AllocateNext ¶
func (r *Allocator) AllocateNext() (uint32, error)
AllocateNext reserves one of the netids from the pool. ErrFull may be returned if there are no netids left.
func (*Allocator) Free ¶
func (r *Allocator) Free() int
Free returns the count of netid left in the range.
type Interface ¶
type Interface interface {
Allocate(uint32) error
AllocateNext() (uint32, error)
Release(uint32) error
Has(uint32) bool
}
Interface manages the allocation of netids out of a range. Interface should be threadsafe.
type NetIDRange ¶
type NetIDRange struct {
Base uint32
Size uint32
}
func NewNetIDRange ¶
func NewNetIDRange(min, max uint32) (*NetIDRange, error)
Click to show internal directories.
Click to hide internal directories.