toolbox

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 17 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 FindLoopbackIPv4Interface

func FindLoopbackIPv4Interface() net.Interface

FindLoopbackIPv4Interface finds the IPv4 loopback interface. It's usually the one with the 127.0.0.1 address but you never know what sort of crazy config you can stumble upon.

func FindPublicIPv4

func FindPublicIPv4() (net.IP, error)

FindPublicIPv4 returns the public IPv4 address of the. If there's more than one public IP(v4) address the first found is returned. Ideally this should use IPv6 but we're currently running in AWS and IPv6 support is so-so.

func FreeTCPPort

func FreeTCPPort() (int, error)

FreeTCPPort returns a free TCP port by using net.ListenTCP on port :0

func FreeUDPPort

func FreeUDPPort() (int, error)

FreeUDPPort returns a free UDP port by using net.ListenUDP on port :0

func GetGRPCDialOpts

func GetGRPCDialOpts(config GRPCClientParam) ([]grpc.DialOption, error)

GetGRPCDialOpts returns dial options for a gRPC client based on the client parameters

func PortOfHostPort

func PortOfHostPort(hostport string) int

PortOfHostPort returns the port number for the host:port string. If there's an error it will panic -- use with caution.

func RandomID

func RandomID() string

RandomID returns a random ID

func RandomLocalEndpoint

func RandomLocalEndpoint() string

RandomLocalEndpoint returns a random endpoint on the loppback interface.

func RandomPublicEndpoint

func RandomPublicEndpoint() string

RandomPublicEndpoint returns a random public endpoint on the host. It will use the first IPv4 address found on the host.

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.

func WaitForCtrlC

func WaitForCtrlC()

WaitForCtrlC waits for an interrupt signal.

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 GRPCClientParam

type GRPCClientParam struct {
	ServerEndpoint     string `kong:"help='Server endpoint',default='localhost:10000'"` // Host:port address of the server
	TLS                bool   `kong:"help='Enable TLS',default='false'"`                // TLS enabled
	CAFile             string `kong:"help='CA certificate file',type='existingfile'"`   // CA cert file
	ServerHostOverride string `kong:"help='Host name override for certificate'"`        // Server name returned from the TLS handshake (for debugging)
}

GRPCClientParam is a parameter struct for gRPC clients.

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