util

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2016 License: MIT Imports: 9 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 IndexOf

func IndexOf(slice []string, element string) int

IndexOf returns the index of element in slice, or -1 if the element is not in slice

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 ReadHostsFile

func ReadHostsFile(file string) ([]string, error)

ReadHostsFile reads a file containing a JSON array of hosts

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 SingleNodeCluster

func SingleNodeCluster(local string, hostsMap map[string][]string) bool

SingleNodeCluster determines if local is the only host:port contained within the hostsMap

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

Bi-directional binding of Time to interger Unix timestamp in JSON

func (*Timestamp) MarshalJSON

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

func (*Timestamp) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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