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
This commit is contained in:
25
balancer/options.go
Normal file
25
balancer/options.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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...)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user