util

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HostportPattern = regexp.MustCompile(`^(\d+.\d+.\d+.\d+):\d+$`)

HostportPattern is regex to match a host:port

Functions

func CaptureHost

func CaptureHost(hostport string) string

CaptureHost takes a host:port and returns the host.

func CheckHostnameIPMismatch

func CheckHostnameIPMismatch(local string, hostsMap map[string][]string) ([]string, error)

CheckHostnameIPMismatch checks for a hostname/IP mismatch in a map of hosts to host:ports. If there is a mismatch, returns the mismatched hosts and an error, otherwise nil and nil.

func CheckLocalMissing

func CheckLocalMissing(local string, hostports []string) error

CheckLocalMissing checks a slice of host:ports for the given local host:port, return an error if not found, otherwise nil.

func HostPortsByHost

func HostPortsByHost(hostports []string) (hostMap map[string][]string)

HostPortsByHost parses a list of host/port conbinations and creates a map of unique hosts each containing a slice of the hostsport instances for each host.

func MS

func MS(d time.Duration) int64

MS returns the number of milliseconds given in a duration

func Min

func Min(first int, rest ...int) int

Min returns the lowest integer and is defined because golang only has a min function for floats and not for ints.

func SelectBool added in v0.8.0

func SelectBool(opt, def bool) bool

SelectBool takes an option and a default value and returns the default value if the option is equal to the zero value, and the option otherwise.

func SelectDuration

func SelectDuration(opt, def time.Duration) time.Duration

SelectDuration takes an option and a default value and returns the default value if the option is equal to zero, and the option otherwise.

func SelectFloat added in v0.5.0

func SelectFloat(opt, def float64) float64

SelectFloat takes an option and a default value and returns the default value if the option is equal to zero, and the option otherwise.

func SelectInt

func SelectInt(opt, def int) int

SelectInt takes an option and a default value and returns the default value if the option is equal to zero, and the option otherwise.

func ShuffleStrings

func ShuffleStrings(strings []string) []string

ShuffleStrings takes a slice of strings and returns a new slice containing the same strings in a random order.

func ShuffleStringsInPlace added in v0.5.0

func ShuffleStringsInPlace(strings []string)

ShuffleStringsInPlace uses the Fisher–Yates shuffle to randomize the strings in place.

func SingleNodeCluster

func SingleNodeCluster(hostport string, hostMap map[string][]string) bool

SingleNodeCluster determines if hostport is the only host:port contained within the hostMap.

func StringInSlice

func StringInSlice(slice []string, str string) bool

StringInSlice returns whether the string is contained within the slice.

func TakeNode

func TakeNode(nodes *[]string, index int) string

TakeNode takes an element from nodes at the given index, or at a random index if index < 0. Mutates nodes.

func TimeNowMS

func TimeNowMS() int64

TimeNowMS returns Unix time in milliseconds for time.Now()

func TimeZero

func TimeZero() time.Time

TimeZero returns a time such that time.IsZero() is true

func UnixMS

func UnixMS(t time.Time) int64

UnixMS returns Unix time in milliseconds for the given time

Types

type Timestamp

type Timestamp time.Time

Timestamp is a bi-directional binding of Time to interger Unix timestamp in JSON.

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the timestamp.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON sets the timestamp to the value in the specified JSON.

Jump to

Keyboard shortcuts

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