60 lines
1,006 B
Go
60 lines
1,006 B
Go
package rabbit
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Option func(*options)
|
|
|
|
func WithConnectTimeout(t time.Duration) Option {
|
|
return func(op *options) {
|
|
op.connectTimeout = t
|
|
}
|
|
}
|
|
|
|
func WithReconnectDelay(t time.Duration) Option {
|
|
return func(op *options) {
|
|
op.reconnectDelay = t
|
|
}
|
|
}
|
|
|
|
func WithReInitDelay(t time.Duration) Option {
|
|
return func(op *options) {
|
|
op.reInitDelay = t
|
|
}
|
|
}
|
|
|
|
func WithResendDelay(t time.Duration) Option {
|
|
return func(op *options) {
|
|
op.resendDelay = t
|
|
}
|
|
}
|
|
|
|
func WithConsumerRateLimit(t time.Duration) Option {
|
|
return func(op *options) {
|
|
op.consumerRateLimit = t
|
|
}
|
|
}
|
|
|
|
func WithConsumerBurstSize(t int) Option {
|
|
return func(op *options) {
|
|
op.consumerBurstSize = t
|
|
}
|
|
}
|
|
|
|
func WithLogger(l *log.Logger) Option {
|
|
return func(op *options) { op.logger = l }
|
|
}
|
|
|
|
func WithLogging(enabled bool) Option {
|
|
return func(op *options) {
|
|
if enabled {
|
|
op.logger = log.New(os.Stdout, "", log.LstdFlags)
|
|
} else {
|
|
op.logger = log.New(io.Discard, "", 0)
|
|
}
|
|
}
|
|
}
|