Documentation
¶
Overview ¶
Package random provides a service implementation creating random numbers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInvalidConfig ¶
IsInvalidConfig asserts invalidConfigError.
Types ¶
type Backoff ¶
type Backoff interface {
// NextBackOff provides the duration expected to wait before retrying an
// action. time.Duration = -1 indicates that no more retry should be
// attempted.
NextBackOff() time.Duration
// Reset sets the backoff back to its initial state.
Reset()
}
Backoff represents the object managing backoff algorithms to retry actions.
type Service ¶
type Service interface {
// CreateMax tries to create one new pseudo random number. The generated
// number is within the range [0 max), which means that max is exclusive.
CreateMax(max int) (int, error)
// CreateNMax tries to create a list of new pseudo random numbers. n
// represents the number of pseudo random numbers in the returned list. The
// generated numbers are within the range [0 max), which means that max is
// exclusive.
CreateNMax(n, max int) ([]int, error)
}
Service creates pseudo random numbers. The service might implement retries using backoff strategies and timeouts.
func NewService ¶
func NewService(config ServiceConfig) (Service, error)
NewService creates a new configured random service.
type ServiceConfig ¶
type ServiceConfig struct {
// BackoffFactory is supposed to be able to create a new spec.Backoff. Retry
// implementations can make use of this to decide when to retry.
BackoffFactory func() Backoff
// RandFactory represents a service returning random values. Here e.g.
// crypto/rand.Int can be used.
RandFactory func(rand io.Reader, max *big.Int) (n *big.Int, err error)
// RandReader represents an instance of a cryptographically strong
// pseudo-random generator. Here e.g. crypto/rand.Reader can be used.
RandReader io.Reader
// Timeout represents the deadline being waited during random number creation
// before returning a timeout error.
Timeout time.Duration
}
ServiceConfig represents the configuration used to create a new random service.
func DefaultServiceConfig ¶
func DefaultServiceConfig() ServiceConfig
DefaultServiceConfig provides a default configuration to create a new random service by best effort.
Click to show internal directories.
Click to hide internal directories.