mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-07 08:07:20 +02:00
⏪ keep compatible with go 1.20
This commit is contained in:
parent
bec363abab
commit
d64b1174af
@ -1,10 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"imuslab.com/zoraxy/mod/dynamicproxy/loadbalance"
|
"imuslab.com/zoraxy/mod/dynamicproxy/loadbalance"
|
||||||
@ -34,22 +33,19 @@ func ReverseProxyUpstreamList(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
activeUpstreams := targetEndpoint.ActiveOrigins
|
activeUpstreams := targetEndpoint.ActiveOrigins
|
||||||
inactiveUpstreams := targetEndpoint.InactiveOrigins
|
inactiveUpstreams := targetEndpoint.InactiveOrigins
|
||||||
slices.SortStableFunc(activeUpstreams, func(i, j *loadbalance.Upstream) int {
|
// Sort the upstreams slice by weight, then by origin domain alphabetically
|
||||||
if i.Weight != j.Weight {
|
sort.Slice(activeUpstreams, func(i, j int) bool {
|
||||||
// sort by weight DESC
|
if activeUpstreams[i].Weight != activeUpstreams[j].Weight {
|
||||||
return cmp.Compare(j.Weight, i.Weight)
|
return activeUpstreams[i].Weight > activeUpstreams[j].Weight
|
||||||
}
|
}
|
||||||
// sort by origin ASC
|
return activeUpstreams[i].OriginIpOrDomain < activeUpstreams[j].OriginIpOrDomain
|
||||||
return cmp.Compare(i.OriginIpOrDomain, j.OriginIpOrDomain)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
slices.SortStableFunc(inactiveUpstreams, func(i, j *loadbalance.Upstream) int {
|
sort.Slice(inactiveUpstreams, func(i, j int) bool {
|
||||||
if i.Weight != j.Weight {
|
if inactiveUpstreams[i].Weight != inactiveUpstreams[j].Weight {
|
||||||
// sort by weight DESC
|
return inactiveUpstreams[i].Weight > inactiveUpstreams[j].Weight
|
||||||
return cmp.Compare(j.Weight, i.Weight)
|
|
||||||
}
|
}
|
||||||
// sort by origin ASC
|
return inactiveUpstreams[i].OriginIpOrDomain < inactiveUpstreams[j].OriginIpOrDomain
|
||||||
return cmp.Compare(i.OriginIpOrDomain, j.OriginIpOrDomain)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
type UpstreamCombinedList struct {
|
type UpstreamCombinedList struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user