40 lines
804 B
Go
40 lines
804 B
Go
package dbx
|
|
|
|
// Option is a functional option for NewCluster.
|
|
type Option func(*Config)
|
|
|
|
// WithLogger sets the logger for the cluster.
|
|
func WithLogger(l Logger) Option {
|
|
return func(c *Config) {
|
|
c.Logger = l
|
|
}
|
|
}
|
|
|
|
// WithMetrics sets the metrics hook for the cluster.
|
|
func WithMetrics(m *MetricsHook) Option {
|
|
return func(c *Config) {
|
|
c.Metrics = m
|
|
}
|
|
}
|
|
|
|
// WithRetry overrides the retry configuration.
|
|
func WithRetry(r RetryConfig) Option {
|
|
return func(c *Config) {
|
|
c.Retry = r
|
|
}
|
|
}
|
|
|
|
// WithHealthCheck overrides the health check configuration.
|
|
func WithHealthCheck(h HealthCheckConfig) Option {
|
|
return func(c *Config) {
|
|
c.HealthCheck = h
|
|
}
|
|
}
|
|
|
|
// ApplyOptions applies functional options to a Config.
|
|
func ApplyOptions(cfg *Config, opts ...Option) {
|
|
for _, o := range opts {
|
|
o(cfg)
|
|
}
|
|
}
|