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:
2026-03-23 00:01:15 +03:00
parent 164c6a5723
commit 62df3a2eb3
21 changed files with 1607 additions and 0 deletions

39
options.go Normal file
View 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)
}
}