Documentation
¶
Index ¶
- Variables
- func ContainsSameElements(s1, s2 interface{}) bool
- func CreateTestAddr(network string) net.Addr
- func Error(a ...interface{}) error
- func ErrorSkipFrames(skip int, a ...interface{}) error
- func Errorf(format string, a ...interface{}) error
- func ErrorfSkipFrames(skip int, format string, a ...interface{}) error
- func IsTrueWithin(trueFunc func() bool, duration time.Duration) error
- func MapKeys(m interface{}) interface{}
- func NewPseudoRand() *rand.Rand
- func RandIntInRange(r *rand.Rand, min, max int) int
- func RetryWithBackoff(opts RetryOptions, fn func() (bool, error)) error
- type Key
- type LRUCache
- type Ordered
- type RetryOptions
- type Retryable
Constants ¶
This section is empty.
Variables ¶
var CachedRand = NewPseudoRand()
CachedRand is a global singleton rand.Rand object cached for one-off purposes to generate random numbers.
Functions ¶
func ContainsSameElements ¶
func ContainsSameElements(s1, s2 interface{}) bool
ContainsSameElements compares, without taking order on the first level, the contents of two slices of the same type. The elements of the slice must have comparisons defined, otherwise a panic will result.
func CreateTestAddr ¶
CreateTestAddr creates an unused address for testing. The "network" parameter should be one of "tcp" or "unix".
func Error ¶
func Error(a ...interface{}) error
Error is a passthrough to fmt.Error, with an additional prefix containing the filename and line number.
func ErrorSkipFrames ¶
ErrorSkipFrames allows the skip count for stack frames to be specified. See the comments for ErrorfSkip.
func Errorf ¶
Errorf is a passthrough to fmt.Errorf, with an additional prefix containing the filename and line number.
func ErrorfSkipFrames ¶
ErrorfSkipFrames allows the skip count for stack frames to be specified. This is useful when generating errors via helper methods. Skip should be specified as the number of additional stack frames between the location at which the error is caused and the location at which the error is generated.
func IsTrueWithin ¶
IsTrueWithin returns an error if the supplied function fails to evaluate to true within the specified duration. The function is invoked at most 50 times over the course of the specified time duration.
func MapKeys ¶
func MapKeys(m interface{}) interface{}
MapKeys takes a map[KeyType]ValueType and returns a slice []KeyType containing the keys of the input map as an interface{} which may be manipulated freely. The implementation relies on reflection and internally requires an extra array, and thus should not be used where a) large maps are expected or b) performance is critical. Example usage: keys := util.MapKeys(map[string]struct{}{"a": {}}).([]string)
func NewPseudoRand ¶
NewPseudoRand returns an instance of math/rand.Rand seeded from crypto/rand so we can easily and cheaply generate unique streams of numbers.
func RandIntInRange ¶
RandIntInRange returns a value in [min, max)
func RetryWithBackoff ¶
func RetryWithBackoff(opts RetryOptions, fn func() (bool, error)) error
RetryWithBackoff implements retry with exponential backoff using the supplied options as parameters. When fn returns false and the number of retry attempts haven't been exhausted, fn is retried. When fn returns true, retry ends. Returns an error if the maximum number of retries is exceeded or if the fn returns an error.
Types ¶
type Key ¶
type Key interface{}
A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type LRUCache ¶
type LRUCache struct { // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specificies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{}) // contains filtered or unexported fields }
LRUCache is an LRU cache. It is not safe for concurrent access.
func NewLRUCache ¶
NewLRUCache creates a new LRUCache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRUCache) RemoveOldest ¶
func (c *LRUCache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
type Ordered ¶
type Ordered interface { // Returns true if the supplied Ordered value // is less than this object. Less(b Ordered) bool }
Ordered values can be compared against each other.
type RetryOptions ¶
type RetryOptions struct { Tag string // Tag for helpful logging of backoffs Backoff time.Duration // Default retry backoff interval MaxBackoff time.Duration // Maximum retry backoff interval Constant float64 // Default backoff constant MaxAttempts int // Maximum number of attempts (0 for infinite) }
RetryOptions provides control of retry loop logic via the RetryWithBackoffOptions method.