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 ¶
- func FindLoopbackIPv4Interface() net.Interface
- func FindPublicIPv4() (net.IP, error)
- func FreeTCPPort() (int, error)
- func FreeUDPPort() (int, error)
- func GetGRPCDialOpts(config GRPCClientParam) ([]grpc.DialOption, error)
- func PortOfHostPort(hostport string) int
- func RandomID() string
- func RandomLocalEndpoint() string
- func RandomPublicEndpoint() string
- func TimeCall(call func(), description string)
- func WaitForCtrlC()
- type ConsoleProgress
- type GRPCClientParam
- type StringSet
- type ZeroconfRegistry
- func (zr *ZeroconfRegistry) Register(kind string, id string, port int) error
- func (zr *ZeroconfRegistry) Resolve(kind string, waitTime time.Duration) ([]string, error)
- func (zr *ZeroconfRegistry) ResolveFirst(kind string, waitTime time.Duration) (string, error)
- func (zr *ZeroconfRegistry) Shutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindLoopbackIPv4Interface ¶
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 ¶
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 ¶
FreeTCPPort returns a free TCP port by using net.ListenTCP on port :0
func FreeUDPPort ¶
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 ¶
PortOfHostPort returns the port number for the host:port string. If there's an error it will panic -- use with caution.
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.
Types ¶
type ConsoleProgress ¶
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 ¶
StringSet is a collection of nodes.
func (*StringSet) Remove ¶
Remove removes a node from the collection. It returns true if a node is removed
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) ResolveFirst ¶
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.