hostlist

package
v0.0.0-...-7c53cb5 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: BSD-2-Clause-Patent Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// MaxRange is the largest host range (hi - lo) supported
	MaxRange = 16384
)

Variables

View Source
var (
	// ErrEmpty indicates empty host list
	ErrEmpty = errors.New("hostlist is empty")
	// ErrNotFound indicates valid hostname could not be found
	ErrNotFound = errors.New("hostname not found")
)

Functions

func Compress

func Compress(stringHosts string) (string, error)

Compress converts the supplied host list into a string of ranged host strings.

func Count

func Count(stringHosts string) (int, error)

Count returns the number of distinct hosts in the supplied host list.

func Expand

func Expand(stringHosts string) (string, error)

Expand converts a ranged host string into an expanded string of all hosts in the supplied range(s).

Types

type HostGroups

type HostGroups map[string]*HostSet

HostGroups maps a set of hosts to a string key value.

func (HostGroups) AddHost

func (hg HostGroups) AddHost(key, host string) error

func (HostGroups) Keys

func (hg HostGroups) Keys() []string

func (HostGroups) String

func (hg HostGroups) String() string

type HostList

type HostList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HostList is a list of hostnames optimized for a "prefixXXXX" naming convention, where XXXX is a decimal, numeric suffix.

func Create

func Create(stringHosts string) (*HostList, error)

Create creates a new HostList from the supplied string representation.

func MustCreate

func MustCreate(stringHosts string) *HostList

MustCreate is like Create but will panic on error.

func (*HostList) Count

func (hl *HostList) Count() int

Count returns the number of hosts in the HostList.

func (*HostList) Delete

func (hl *HostList) Delete(stringHosts string) (int, error)

Delete removes all hosts in the supplied string representation of a HostList. Returns the number of hosts successfully deleted.

func (*HostList) DeleteHost

func (hl *HostList) DeleteHost(stringHost string) error

DeleteHost removes the first host that matches the supplied hostname. Returns an error if the HostList is empty or the hostname is not found.

func (*HostList) DeleteNth

func (hl *HostList) DeleteNth(n int) error

DeleteNth removes the host at position N in the HostList. Returns an error if the HostList is empty or the index is incorrect.

func (*HostList) DerangedString

func (hl *HostList) DerangedString() string

DerangedString returns a string containing the hostnames of every host in the HostList, without any bracketing.

func (*HostList) Find

func (hl *HostList) Find(stringHost string) (int, bool)

Find searches the HostList for the given hostname. Returns the index of the host and true if found; -1 and false if not.

func (*HostList) Intersects

func (hl *HostList) Intersects(stringHosts string) (*HostList, error)

Intersects returns a *HostList containing hosts which are in both this HostList and the supplied hosts string.

func (*HostList) IsEmpty

func (hl *HostList) IsEmpty() bool

IsEmpty returns true if the HostList has zero hosts.

func (*HostList) Nth

func (hl *HostList) Nth(n int) (string, error)

Nth returns the string representation of the n-th host in the HostList. Returns an error if the index is invalid.

func (*HostList) Pop

func (hl *HostList) Pop() (hostName string, err error)

Pop returns the string representation of the last host pushed onto the HostList and then removes it from the HostList. Returns an error if the HostList is empty.

func (*HostList) PopRange

func (hl *HostList) PopRange() (hostRange string, err error)

PopRange returns the string representation of the last bracketed list of hosts. All hosts in the returned list are removed from the HostList. Returns an error if the HostList is empty.

func (*HostList) Push

func (hl *HostList) Push(stringHosts string) error

Push adds a string representation of hostnames to this HostList.

func (*HostList) PushHost

func (hl *HostList) PushHost(stringHost string) error

PushHost adds a single host to this HostList.

func (*HostList) PushList

func (hl *HostList) PushList(other *HostList)

PushList adds the supplied HostList onto this HostList.

func (*HostList) RangedString

func (hl *HostList) RangedString() string

RangedString returns a string containing a bracketed HostList representation.

func (*HostList) ReplaceList

func (hl *HostList) ReplaceList(other *HostList)

ReplaceList replaces this HostList's contents with the supplied HostList.

func (*HostList) Shift

func (hl *HostList) Shift() (hostName string, err error)

Shift returns the string representation of the first host pushed onto the HostList and then removes it from the HostList. Returns an error if the HostList is empty.

func (*HostList) ShiftRange

func (hl *HostList) ShiftRange() (hostRange string, err error)

ShiftRange returns the string representation of the first bracketed list of hosts. All hosts in the returned list are removed from the HostList. Returns an error if the HostList is empty.

func (*HostList) Slice

func (hl *HostList) Slice() []string

Slice returns a string slice containing the hostnames of every host in the HostList.

func (*HostList) String

func (hl *HostList) String() string

String returns a ranged string representation of the HostList.

func (*HostList) Uniq

func (hl *HostList) Uniq()

Uniq forces a sort operation on the HostList and removes duplicates.

func (*HostList) Within

func (hl *HostList) Within(stringHosts string) (bool, error)

Within returns true if all hosts in the supplied hosts are contained within the HostList, false otherwise.

type HostSet

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

HostSet is a special case of HostList which never contains duplicates and is always sorted alphanumerically based on prefix.

func CreateSet

func CreateSet(stringHosts string) (*HostSet, error)

CreateSet creates a new HostSet from the supplied string representation.

func MustCreateSet

func MustCreateSet(stringHosts string) *HostSet

MustCreateSet is like CreateSet but will panic on error.

func (*HostSet) Count

func (hs *HostSet) Count() int

Count returns the number of hosts in the HostSet.

func (*HostSet) Delete

func (hs *HostSet) Delete(stringHosts string) (int, error)

Delete removes a host or list of hosts from the HostSet. Returns the number of hosts successfully removed.

func (*HostSet) DerangedString

func (hs *HostSet) DerangedString() string

DerangedString returns a string containing the hostnames of every host in the HostSet, without any bracketing.

func (*HostSet) Insert

func (hs *HostSet) Insert(stringHosts string) (int, error)

Insert adds a host or list of hosts to the HostSet. Returns the number of non-duplicate hosts successfully added.

func (*HostSet) Intersects

func (hs *HostSet) Intersects(stringHosts string) (*HostSet, error)

Intersects returns a *HostSet containing hosts which are in both this HostSet and the supplied hosts string.

func (*HostSet) MarshalJSON

func (hs *HostSet) MarshalJSON() ([]byte, error)

MarshalJSON outputs JSON representation of HostSet.

func (*HostSet) Merge

func (hs *HostSet) Merge(other *HostSet) error

Merge merges the supplied HostSet into this one.

func (*HostSet) Pop

func (hs *HostSet) Pop() (string, error)

Pop returns the string representation of the last host pushed onto the HostSet and then removes it from the HostSet. Returns an error if the HostSet is empty

func (*HostSet) PopRange

func (hs *HostSet) PopRange() (string, error)

PopRange returns the string representation of the last bracketed list of hosts. All hosts in the returned list are removed from the HostSet. Returns an error if the HostSet is empty.

func (*HostSet) RangedString

func (hs *HostSet) RangedString() string

RangedString returns a string containing a bracketed HostSet representation.

func (*HostSet) Replace

func (hs *HostSet) Replace(other *HostSet)

Replace replaces this HostSet with the contents of the supplied HostSet.

func (*HostSet) Shift

func (hs *HostSet) Shift() (string, error)

Shift returns the string representation of the first host pushed onto the HostSet and then removes it from the HostSet. Returns an error if the HostSet is empty

func (*HostSet) ShiftRange

func (hs *HostSet) ShiftRange() (string, error)

ShiftRange returns the string representation of the first bracketed list of hosts. All hosts in the returned list are removed from the HostSet. Returns an error if the HostSet is empty.

func (*HostSet) Slice

func (hs *HostSet) Slice() []string

Slice returns a string slice containing the hostnames of every host in the HostSet.

func (*HostSet) String

func (hs *HostSet) String() string

func (*HostSet) Within

func (hs *HostSet) Within(stringHosts string) (bool, error)

Within returns true if all hosts in the supplied hosts are contained within the HostSet, false otherwise.

type NumericList

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

NumericList implements a subset of the HostList interface and is designed for use with lists of numbers.

func CreateNumericList

func CreateNumericList(stringRanges string) (*NumericList, error)

CreateNumericList creates a NumericList that contains numeric entries and ranges from the supplied string representation.

func NewNumericList

func NewNumericList(values ...uint) *NumericList

NewNumericList creates an initialized NumericList with optional starting values.

func (*NumericList) Add

func (nl *NumericList) Add(i uint)

Add adds the supplied numeric entry to the NumericList.

func (*NumericList) Count

func (nl *NumericList) Count() int

Count returns the number of numeric entries in the NumericList.

func (*NumericList) Delete

func (nl *NumericList) Delete(i uint)

Delete removes the supplied numeric entry from the NumericList. No-op if the entry is not present.

func (*NumericList) Merge

func (nl *NumericList) Merge(other *NumericList)

Merge merges the contents of this NumericList with those of the other NumericList.

func (*NumericList) RangedString

func (nl *NumericList) RangedString() string

func (*NumericList) Replace

func (nl *NumericList) Replace(other *NumericList)

Replace replaces the contents of this NumericList with those from the other NumericList.

func (*NumericList) Slice

func (nl *NumericList) Slice() (out []uint)

Slice returns a slice of the numeric entries in the NumericList.

func (*NumericList) String

func (nl *NumericList) String() string

func (*NumericList) Uniq

func (nl *NumericList) Uniq()

Uniq sorts and removes duplicate entries from the NumericList.

type NumericSet

type NumericSet struct {
	NumericList
}

NumericSet is a special case of a NumericList that contains unique numeric entries.

func CreateNumericSet

func CreateNumericSet(stringRanges string) (*NumericSet, error)

CreateNumericSet creates a NumericSet containing unique numeric entries and ranges from the supplied string representation.

func NewNumericSet

func NewNumericSet(values ...uint) *NumericSet

NewNumericSet creates an initialized NumericSet with optional starting values.

func (*NumericSet) Add

func (ns *NumericSet) Add(i uint)

Add adds the supplied numeric entry to the NumericSet.

func (*NumericSet) Delete

func (ns *NumericSet) Delete(i uint)

Delete removes the supplied numeric entry from the NumericSet. No-op if the entry is not present.

func (*NumericSet) Merge

func (ns *NumericSet) Merge(other *NumericSet)

Merge merges the contents of this NumericSet with those of the other NumericSet.

func (*NumericSet) Replace

func (ns *NumericSet) Replace(other *NumericSet)

Replace replaces the contents of this NumericSet with those from the other NumericSet.

Jump to

Keyboard shortcuts

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