Files
httpx/balancer/failover.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

18 lines
427 B
Go

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
}