Implements balancer middleware with URL rewriting per-request: - RoundRobin, Failover, and WeightedRandom endpoint selection strategies - Background HealthChecker with configurable probe interval and path - Thread-safe health state tracking with sync.RWMutex
26 lines
657 B
Go
26 lines
657 B
Go
package balancer
|
|
|
|
// options holds configuration for the load balancer transport.
|
|
type options struct {
|
|
strategy Strategy // default RoundRobin
|
|
healthChecker *HealthChecker // optional
|
|
}
|
|
|
|
// Option configures the load balancer transport.
|
|
type Option func(*options)
|
|
|
|
// WithStrategy sets the endpoint selection strategy.
|
|
// If not specified, RoundRobin is used.
|
|
func WithStrategy(s Strategy) Option {
|
|
return func(o *options) {
|
|
o.strategy = s
|
|
}
|
|
}
|
|
|
|
// WithHealthCheck enables active health checking of endpoints.
|
|
func WithHealthCheck(opts ...HealthOption) Option {
|
|
return func(o *options) {
|
|
o.healthChecker = newHealthChecker(opts...)
|
|
}
|
|
}
|