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