mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-10 04:30:20 +02:00
Maintenance: unique choices from hardcoded servers
This commit is contained in:
@@ -2,7 +2,6 @@ package constants
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
@@ -13,31 +12,21 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CyberghostRegionChoices() (choices []string) {
|
func CyberghostRegionChoices() (choices []string) {
|
||||||
uniqueChoices := map[string]struct{}{}
|
servers := CyberghostServers()
|
||||||
for _, server := range CyberghostServers() {
|
choices = make([]string, len(servers))
|
||||||
uniqueChoices[server.Region] = struct{}{}
|
for i := range servers {
|
||||||
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
for choice := range uniqueChoices {
|
return makeUnique(choices)
|
||||||
choices = append(choices, choice)
|
|
||||||
}
|
|
||||||
sort.Slice(choices, func(i, j int) bool {
|
|
||||||
return choices[i] < choices[j]
|
|
||||||
})
|
|
||||||
return choices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CyberghostGroupChoices() (choices []string) {
|
func CyberghostGroupChoices() (choices []string) {
|
||||||
uniqueChoices := map[string]struct{}{}
|
servers := CyberghostServers()
|
||||||
for _, server := range CyberghostServers() {
|
choices = make([]string, len(servers))
|
||||||
uniqueChoices[server.Group] = struct{}{}
|
for i := range servers {
|
||||||
|
choices[i] = servers[i].Group
|
||||||
}
|
}
|
||||||
for choice := range uniqueChoices {
|
return makeUnique(choices)
|
||||||
choices = append(choices, choice)
|
|
||||||
}
|
|
||||||
sort.Slice(choices, func(i, j int) bool {
|
|
||||||
return choices[i] < choices[j]
|
|
||||||
})
|
|
||||||
return choices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package constants
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
@@ -13,45 +12,30 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func MullvadCountryChoices() (choices []string) {
|
func MullvadCountryChoices() (choices []string) {
|
||||||
uniqueChoices := map[string]struct{}{}
|
servers := MullvadServers()
|
||||||
for _, server := range MullvadServers() {
|
choices = make([]string, len(servers))
|
||||||
uniqueChoices[server.Country] = struct{}{}
|
for i := range servers {
|
||||||
|
choices[i] = servers[i].Country
|
||||||
}
|
}
|
||||||
for choice := range uniqueChoices {
|
return makeUnique(choices)
|
||||||
choices = append(choices, choice)
|
|
||||||
}
|
|
||||||
sort.Slice(choices, func(i, j int) bool {
|
|
||||||
return choices[i] < choices[j]
|
|
||||||
})
|
|
||||||
return choices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MullvadCityChoices() (choices []string) {
|
func MullvadCityChoices() (choices []string) {
|
||||||
uniqueChoices := map[string]struct{}{}
|
servers := MullvadServers()
|
||||||
for _, server := range MullvadServers() {
|
choices = make([]string, len(servers))
|
||||||
uniqueChoices[server.City] = struct{}{}
|
for i := range servers {
|
||||||
|
choices[i] = servers[i].City
|
||||||
}
|
}
|
||||||
for choice := range uniqueChoices {
|
return makeUnique(choices)
|
||||||
choices = append(choices, choice)
|
|
||||||
}
|
|
||||||
sort.Slice(choices, func(i, j int) bool {
|
|
||||||
return choices[i] < choices[j]
|
|
||||||
})
|
|
||||||
return choices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MullvadISPChoices() (choices []string) {
|
func MullvadISPChoices() (choices []string) {
|
||||||
uniqueChoices := map[string]struct{}{}
|
servers := MullvadServers()
|
||||||
for _, server := range MullvadServers() {
|
choices = make([]string, len(servers))
|
||||||
uniqueChoices[server.ISP] = struct{}{}
|
for i := range servers {
|
||||||
|
choices[i] = servers[i].ISP
|
||||||
}
|
}
|
||||||
for choice := range uniqueChoices {
|
return makeUnique(choices)
|
||||||
choices = append(choices, choice)
|
|
||||||
}
|
|
||||||
sort.Slice(choices, func(i, j int) bool {
|
|
||||||
return choices[i] < choices[j]
|
|
||||||
})
|
|
||||||
return choices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:dupl,lll
|
//nolint:dupl,lll
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func NordvpnRegionChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gomnd
|
//nolint:gomnd
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func PIAGeoChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func PrivadoHostnameChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Hostname
|
choices[i] = servers[i].Hostname
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrivadoServers() []models.PrivadoServer {
|
func PrivadoServers() []models.PrivadoServer {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func PurevpnRegionChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PurevpnCountryChoices() (choices []string) {
|
func PurevpnCountryChoices() (choices []string) {
|
||||||
@@ -29,7 +29,7 @@ func PurevpnCountryChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Country
|
choices[i] = servers[i].Country
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PurevpnCityChoices() (choices []string) {
|
func PurevpnCityChoices() (choices []string) {
|
||||||
@@ -38,7 +38,7 @@ func PurevpnCityChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].City
|
choices[i] = servers[i].City
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func SurfsharkRegionChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TorguardCountryChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Country
|
choices[i] = servers[i].Country
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TorguardCityChoices() (choices []string) {
|
func TorguardCityChoices() (choices []string) {
|
||||||
@@ -27,7 +27,7 @@ func TorguardCityChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].City
|
choices[i] = servers[i].City
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TorguardHostnamesChoices() (choices []string) {
|
func TorguardHostnamesChoices() (choices []string) {
|
||||||
@@ -36,7 +36,7 @@ func TorguardHostnamesChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Hostname
|
choices[i] = servers[i].Hostname
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package constants
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
|
func makeUnique(slice []string) (uniques []string) {
|
||||||
|
set := make(map[string]struct{}, len(slice))
|
||||||
|
for _, element := range slice {
|
||||||
|
set[element] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
uniques = make([]string, 0, len(set))
|
||||||
|
for element := range set {
|
||||||
|
uniques = append(uniques, element)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(uniques, func(i, j int) bool {
|
||||||
|
return uniques[i] < uniques[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
return uniques
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ func VyprvpnRegionChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func VyprvpnServers() []models.VyprvpnServer {
|
func VyprvpnServers() []models.VyprvpnServer {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func WindscribeRegionChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Region
|
choices[i] = servers[i].Region
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WindscribeCityChoices() (choices []string) {
|
func WindscribeCityChoices() (choices []string) {
|
||||||
@@ -27,7 +27,7 @@ func WindscribeCityChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].City
|
choices[i] = servers[i].City
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WindscribeHostnameChoices() (choices []string) {
|
func WindscribeHostnameChoices() (choices []string) {
|
||||||
@@ -36,7 +36,7 @@ func WindscribeHostnameChoices() (choices []string) {
|
|||||||
for i := range servers {
|
for i := range servers {
|
||||||
choices[i] = servers[i].Hostname
|
choices[i] = servers[i].Hostname
|
||||||
}
|
}
|
||||||
return choices
|
return makeUnique(choices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WindscribeServers() []models.WindscribeServer {
|
func WindscribeServers() []models.WindscribeServer {
|
||||||
|
|||||||
Reference in New Issue
Block a user