util

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 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(a, b int) int

Min returns min(a,b)

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 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 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