Files
httpx/balancer/options.go
Aleksey Shakhmatov 8d322123a4 Add load balancer with round-robin, failover, and weighted strategies
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
2026-03-20 14:22:07 +03:00

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...)
}
}