mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-06 07:37:21 +02:00
📝 randIndex for fallbackUpstreams random
This commit is contained in:
parent
e53c3cf3c4
commit
8a8ec1cb0b
@ -130,8 +130,8 @@ func getRandomUpstreamByWeight(upstreams []*Upstream) (*Upstream, int, error) {
|
|||||||
if totalWeight == 0 {
|
if totalWeight == 0 {
|
||||||
if len(fallbackUpstreams) > 0 {
|
if len(fallbackUpstreams) > 0 {
|
||||||
// Randomly select one of the fallback upstreams
|
// Randomly select one of the fallback upstreams
|
||||||
index := rand.Intn(len(fallbackUpstreams))
|
randIndex := rand.Intn(len(fallbackUpstreams))
|
||||||
return fallbackUpstreams[index].Upstream, fallbackUpstreams[index].Index, nil
|
return fallbackUpstreams[randIndex].Upstream, fallbackUpstreams[randIndex].Index, nil
|
||||||
}
|
}
|
||||||
// No upstreams available at all
|
// No upstreams available at all
|
||||||
return nil, -1, errors.New("no valid upstream servers available")
|
return nil, -1, errors.New("no valid upstream servers available")
|
||||||
@ -153,8 +153,8 @@ func getRandomUpstreamByWeight(upstreams []*Upstream) (*Upstream, int, error) {
|
|||||||
|
|
||||||
// If we reach here, it means we should return a fallback upstream if available
|
// If we reach here, it means we should return a fallback upstream if available
|
||||||
if len(fallbackUpstreams) > 0 {
|
if len(fallbackUpstreams) > 0 {
|
||||||
index := rand.Intn(len(fallbackUpstreams))
|
randIndex := rand.Intn(len(fallbackUpstreams))
|
||||||
return fallbackUpstreams[index].Upstream, fallbackUpstreams[index].Index, nil
|
return fallbackUpstreams[randIndex].Upstream, fallbackUpstreams[randIndex].Index, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, -1, errors.New("failed to pick an upstream origin server")
|
return nil, -1, errors.New("failed to pick an upstream origin server")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user