Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
DurationToHuman converts a duration to a human readable format
func FileExists ¶
func RandomString ¶
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
NewLimiter creates a new Limiter
func (*Limiter) Add ¶ added in v1.1.3
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) Set ¶ added in v1.1.3
Set sets the value of the limiter to n. This function ignores the limit. It is meant to set the value based on reality.