chore(storage): common sorting for all servers
This commit is contained in:
@@ -5,6 +5,7 @@ package protonvpn
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
@@ -63,7 +64,7 @@ func (u *Updater) GetServers(ctx context.Context, minServers int) (
|
||||
|
||||
servers = ipToServer.toServersSlice()
|
||||
|
||||
sortServers(servers)
|
||||
sort.Sort(models.SortableServers(servers))
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func sortServers(servers []models.Server) {
|
||||
sort.Slice(servers, func(i, j int) bool {
|
||||
a, b := servers[i], servers[j]
|
||||
if a.Country == b.Country { //nolint:nestif
|
||||
if a.Region == b.Region {
|
||||
if a.City == b.City {
|
||||
if a.ServerName == b.ServerName {
|
||||
return a.Hostname < b.Hostname
|
||||
}
|
||||
return a.ServerName < b.ServerName
|
||||
}
|
||||
return a.City < b.City
|
||||
}
|
||||
return a.Region < b.Region
|
||||
}
|
||||
return a.Country < b.Country
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user