util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReached = errors.New("limit reached")

ErrLimitReached is the error returned by the Limiter and LimitWriter when the predefined limit has been reached

Functions

func DurationToHuman added in v1.3.0

func DurationToHuman(d time.Duration) (str string)

DurationToHuman converts a duration to a human readable format

func FileExists

func FileExists(filename string) bool

func RandomString

func RandomString(length int) string

RandomString returns a random string with a given length

Types

type Limiter added in v1.1.3

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

Limiter is a helper that allows adding values up to a well-defined limit. Once the limit is reached ErrLimitReached will be returned. Limiter may be used by multiple goroutines.

func NewLimiter added in v1.1.3

func NewLimiter(limit int64) *Limiter

NewLimiter creates a new Limiter

func (*Limiter) Add added in v1.1.3

func (l *Limiter) Add(n int64) error

Add adds n to the limiters internal value, but only if the limit has not been reached. If the limit would be exceeded after adding n, ErrLimitReached is returned.

func (*Limiter) Limit added in v1.1.3

func (l *Limiter) Limit() int64

Limit returns the defined limit

func (*Limiter) Set added in v1.1.3

func (l *Limiter) Set(n int64)

Set sets the value of the limiter to n. This function ignores the limit. It is meant to set the value based on reality.

func (*Limiter) Sub added in v1.1.3

func (l *Limiter) Sub(n int64)

Sub subtracts a value from the limiters internal value

func (*Limiter) Value added in v1.1.3

func (l *Limiter) Value() int64

Value returns the internal value of the limiter

Jump to

Keyboard shortcuts

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