util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const RaceEnabled = false

RaceEnabled indicates that program/tests are running with race detection enabled or not. Some tests may chose to skip execution when race detection is on.

Variables

View Source
var ByteOrder binary.ByteOrder

ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.

View Source
var ErrUnableToLockNow = errors.New("unable to acquire the lock at the moment")

ErrUnableToLockNow is used to indicate that a lock cannot be immediately acquired.

Functions

func CloseFile added in v0.4.0

func CloseFile(err error, f io.Closer) error

CloseFile closes the given file and report the possible error only if the given error `err` is not already set.

func EnsureBufBigEnough

func EnsureBufBigEnough(buf []byte, needed int) []byte

EnsureBufBigEnough checks that given buffer is big enough to hold 'needed' bytes, otherwise returns a buffer of a size of at least 'needed' bytes.

func FriendlyBytes added in v0.4.0

func FriendlyBytes(bytes int64) string

FriendlyBytes returns a string with the given bytes int64 represented as a size, such as 1KB, 10MB, etc...

func IsSubjectValid added in v0.4.0

func IsSubjectValid(subject string) bool

IsSubjectValid returns false if the string if any of this condition apply: - is empty - contains wildcards `*` or `>` - token separator `.` is first or last - there are two consecutives token separators `.`

func ReadInt

func ReadInt(r io.Reader) (int, error)

ReadInt reads an int (4 bytes) from the reader using ByteOrder.

func WriteInt

func WriteInt(w io.Writer, v int) error

WriteInt writes an int (4 bytes) to the given writer using ByteOrder.

Types

type BackoffTimeCheck added in v0.4.0

type BackoffTimeCheck struct {
	// contains filtered or unexported fields
}

BackoffTimeCheck allows to execute some code, but not too often.

func NewBackoffTimeCheck added in v0.4.0

func NewBackoffTimeCheck(minFrequency time.Duration, factor int, maxFrequency time.Duration) (*BackoffTimeCheck, error)

NewBackoffTimeCheck creates an instance of BackoffTimeCheck. The `minFrequency` indicates how frequently BackoffTimeCheck.Ok() can return true. When Ok() returns true, the allowed frequency is multiplied by `factor`. The resulting frequency is capped by `maxFrequency`.

func (*BackoffTimeCheck) Ok added in v0.4.0

func (bp *BackoffTimeCheck) Ok() bool

Ok returns true for the first time it is invoked after creation of the object or call to Reset(), or after an amount of time (based on the last success and the allowed frequency) has elapsed. When at the maximum frequency, if this call is made after a delay at least equal to 3x the max frequency (or in other words, 2x after what was the target for the next print), then the object is auto-reset.

func (*BackoffTimeCheck) Reset added in v0.4.0

func (bp *BackoffTimeCheck) Reset()

Reset the state so that next call to BackoffPrint.Ok() will return true.

type LockFile added in v0.4.0

type LockFile interface {
	io.Closer
	IsClosed() bool
}

LockFile is an interface for lock files utility.

func CreateLockFile added in v0.4.0

func CreateLockFile(file string) (LockFile, error)

CreateLockFile attempt to lock the given file, creating it if necessary. On success, the file is returned, otherwise an error is returned. The file returned should be closed to release the lock quicker than if left to the operating systen.

Jump to

Keyboard shortcuts

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