toolbox

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package toolbox contains various helper and utility functions that the library uses. The gut reaction is to call this "toolbox" but it's not an exhaustive collection of utilities but rather a collection small helper functions that keeps on proving useful.It's not too different from a toolbox in the corner of the workshop with all sorts of mangled tools modified to fit a particular purpose :)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomID

func RandomID() string

RandomID returns a random ID

func TimeCall

func TimeCall(call func(), description string)

TimeCall times the call and prints out the execution time in milliseconds in the go standard log.

Types

type ConsoleProgress

type ConsoleProgress struct {
	Max     int
	Current int
}

ConsoleProgress prints an 80-character progress bar on the console for values between [0, Max]

func (*ConsoleProgress) Print

func (c *ConsoleProgress) Print(val int)

Print prints a 80-character wide progress bar on the console.

type StringSet

type StringSet struct {
	Strings []string
	Mutex   *sync.RWMutex
}

StringSet is a collection of nodes.

func NewStringSet

func NewStringSet() StringSet

NewStringSet creates a new string set instance

func (*StringSet) Add

func (s *StringSet) Add(node string) bool

Add adds a new node to the collection. It returns true if the node is added

func (*StringSet) Clear

func (s *StringSet) Clear()

Clear empties the string set

func (*StringSet) Contains

func (s *StringSet) Contains(e string) bool

Contains returns true if the set contains the string

func (*StringSet) List

func (s *StringSet) List() []string

List returns a list of the nodes in the collection

func (*StringSet) Remove

func (s *StringSet) Remove(node string) bool

Remove removes a node from the collection. It returns true if a node is removed

func (*StringSet) Size

func (s *StringSet) Size() int

Size returns the size of the node collection

func (*StringSet) Sync

func (s *StringSet) Sync(nodes ...string) bool

Sync synchronizes the collection with the IDs in the array and returns true if there's a change.

type ZeroconfRegistry

type ZeroconfRegistry struct {
	ClusterName string
	// contains filtered or unexported fields
}

ZeroconfRegistry is the type for a zeroconf registry. It will announce one or more endpoints via mDNS/Zeroconf/Bonjour until Shutdown() is called.

func NewZeroconfRegistry

func NewZeroconfRegistry(clusterName string) *ZeroconfRegistry

NewZeroconfRegistry creates a new zeroconf server

func (*ZeroconfRegistry) Register

func (zr *ZeroconfRegistry) Register(kind string, id string, port int) error

Register registers a new endpoint. Only one endpoint can be created at a time The ID parameter is an unique ID.

func (*ZeroconfRegistry) Resolve

func (zr *ZeroconfRegistry) Resolve(kind string, waitTime time.Duration) ([]string, error)

Resolve looks for another service

func (*ZeroconfRegistry) ResolveFirst

func (zr *ZeroconfRegistry) ResolveFirst(kind string, waitTime time.Duration) (string, error)

ResolveFirst looks for another service and returns only the first matching element

func (*ZeroconfRegistry) Shutdown

func (zr *ZeroconfRegistry) Shutdown()

Shutdown shuts down the Zeroconf server.

Directories

Path Synopsis
Package fsmtool contains tools for creating FSMs, particularly transitioning between states.
Package fsmtool contains tools for creating FSMs, particularly transitioning between states.

Jump to

Keyboard shortcuts

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