utils

package
v0.0.0-...-08a0563 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSemVer = errors.New("invalid semver format")

ErrInvalidSemVer indicates a semver value that is not correctly formatted.

View Source
var Nothing = Sentinel{}

Nothing represents an empty value, used for values in set-type maps.

Functions

func CompareSemVer

func CompareSemVer(lhs, rhs string) (int, error)

CompareSemVer compares two SemVer values, and returns -1 if lhs is less (older) than rhs, 1 if lhs is greater (newer) than rhs, and 0 if they are equivalent. The error will be ErrInvalidSemVer if either value is not valid semver format, or nil otherwise.

func DistinctStrings

func DistinctStrings(arrays ...[]string) []string

DistinctStrings returns the array of unique values among the given string arrays.

func Execute

func Execute(args ...string) (exitCode int, output []byte, err error)

Execute a check and return its exit code. Based on http://stackoverflow.com/a/10385867/7426 and http://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/.

func HumanReadableBytesDecimal

func HumanReadableBytesDecimal(bytes int64, sigdig int) string

HumanReadableBytesDecimal returns decimal-style human-readable byte count representation.

func HumanReadableBytesSI

func HumanReadableBytesSI(bytes int64, sigdig int) string

HumanReadableBytesSI returns SI-style human-readable byte count representation.

func LaterDate

func LaterDate(t1, t2 time.Time) time.Time

LaterDate returns the later of two dates.

func LatestDate

func LatestDate(dates ...time.Time) time.Time

LatestDate returns the latest of the given dates.

func NewTimeUUID

func NewTimeUUID() uuid.UUID

NewTimeUUID generates a UUID-style 16-byte identifier, with the first 8 bytes being the current time in nanoseconds since the Unix epoch, and the last 8 bytes being randomly set, ensuring that the RFC4122 variant bit is not set. These can be sorted and compared lexically as if they were a timestamp, but remain resilient against collisions and do not expose MAC addess or other host information.

func StringToArgs

func StringToArgs(in string) []string

StringToArgs converts a shell-style string into an argv-style array.

func TimeUUID

func TimeUUID(t time.Time) uuid.UUID

TimeUUID generates a UUID-style 16-byte identifier, with the first 8 bytes being the given Time's nanoseconds since the Unix epoch, and the last 8 bytes being zero. This can be used for lexical comparison of time-based UUIDs.

Types

type BufferPool

type BufferPool struct {
	BufferSize int
	MaxSize    int
	// contains filtered or unexported fields
}

BufferPool maintains a pool of reusable byte buffers.

func NewBufferPool

func NewBufferPool(initialSize, maxSize, poolSize int) *BufferPool

NewBufferPool constructs a new buffer pool and initializes half the pool.

func (*BufferPool) Get

func (p *BufferPool) Get() *bytes.Buffer

Get a buffer from the pool. Consumers should Give() the buffer back after use.

func (*BufferPool) Give

func (p *BufferPool) Give(b *bytes.Buffer)

Give a buffer back to the pool. Consumers should not use the buffer after calling Give.

type Repeater

type Repeater struct {
	Interval time.Duration
	C        SentinelChannel
	// contains filtered or unexported fields
}

Repeater repeats calls to a channel, allowing for changes in repeat interval while running without disturbing cadence.

func StartRepeater

func StartRepeater(interval time.Duration) *Repeater

StartRepeater starts a new repeater with the given interval. The first call to the channel will be after interval.

func (*Repeater) Stop

func (r *Repeater) Stop()

Stop the repeater and close the channel. The Repeater cannot be reused.

func (*Repeater) UpdateInterval

func (r *Repeater) UpdateInterval(newInterval time.Duration)

UpdateInterval updates the interval this Repeater repeats at. The next call to the channel will be newInterval from the last time it fired.

type Sentinel

type Sentinel struct{}

Sentinel is an empty struct used for flags and signals.

type SentinelChannel

type SentinelChannel chan Sentinel

SentinelChannel is a low-overhead signalling channel.

func (SentinelChannel) Signal

func (sc SentinelChannel) Signal()

Signal sends an object over the channel.

Jump to

Keyboard shortcuts

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