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:
17
balancer/failover.go
Normal file
17
balancer/failover.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package balancer
|
||||
|
||||
type failover struct{}
|
||||
|
||||
// Failover returns a strategy that always picks the first healthy endpoint.
|
||||
// If the primary endpoint is unhealthy, it falls back to the next available
|
||||
// healthy endpoint in order.
|
||||
func Failover() Strategy {
|
||||
return &failover{}
|
||||
}
|
||||
|
||||
func (f *failover) Next(healthy []Endpoint) (Endpoint, error) {
|
||||
if len(healthy) == 0 {
|
||||
return Endpoint{}, ErrNoHealthy
|
||||
}
|
||||
return healthy[0], nil
|
||||
}
|
||||
Reference in New Issue
Block a user