Simply return first host if there is only one possible upstream host
@@ -26,6 +26,10 @@ func (b *WeightBalancer) Elect(hosts []*Target) (*Target, error) {
return nil, ErrEmptyBackendList
}
+ if len(hosts) == 1 {
+ return hosts[0], nil
+ }
+
totalWeight := 0
for _, host := range hosts {
totalWeight += host.Weight
