Add dbx library: PostgreSQL cluster with master/replica routing, retry, health checking
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
39
options.go
Normal file
39
options.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user