chore(validation): move functions from constants
- Move validation functions from `internal/constants` to `internal/configuration/settings/validation` - Concatenate all OpenVPN constants in `internal/constants/openvpn.go`
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/validation"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gotree"
|
||||
@@ -71,84 +72,84 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
|
||||
case constants.Custom:
|
||||
case constants.Cyberghost:
|
||||
servers := allServers.GetCyberghost()
|
||||
countryChoices = constants.CyberghostCountryChoices(servers)
|
||||
hostnameChoices = constants.CyberghostHostnameChoices(servers)
|
||||
countryChoices = validation.CyberghostCountryChoices(servers)
|
||||
hostnameChoices = validation.CyberghostHostnameChoices(servers)
|
||||
case constants.Expressvpn:
|
||||
servers := allServers.GetExpressvpn()
|
||||
countryChoices = constants.ExpressvpnCountriesChoices(servers)
|
||||
cityChoices = constants.ExpressvpnCityChoices(servers)
|
||||
hostnameChoices = constants.ExpressvpnHostnameChoices(servers)
|
||||
countryChoices = validation.ExpressvpnCountriesChoices(servers)
|
||||
cityChoices = validation.ExpressvpnCityChoices(servers)
|
||||
hostnameChoices = validation.ExpressvpnHostnameChoices(servers)
|
||||
case constants.Fastestvpn:
|
||||
servers := allServers.GetFastestvpn()
|
||||
countryChoices = constants.FastestvpnCountriesChoices(servers)
|
||||
hostnameChoices = constants.FastestvpnHostnameChoices(servers)
|
||||
countryChoices = validation.FastestvpnCountriesChoices(servers)
|
||||
hostnameChoices = validation.FastestvpnHostnameChoices(servers)
|
||||
case constants.HideMyAss:
|
||||
servers := allServers.GetHideMyAss()
|
||||
countryChoices = constants.HideMyAssCountryChoices(servers)
|
||||
regionChoices = constants.HideMyAssRegionChoices(servers)
|
||||
cityChoices = constants.HideMyAssCityChoices(servers)
|
||||
hostnameChoices = constants.HideMyAssHostnameChoices(servers)
|
||||
countryChoices = validation.HideMyAssCountryChoices(servers)
|
||||
regionChoices = validation.HideMyAssRegionChoices(servers)
|
||||
cityChoices = validation.HideMyAssCityChoices(servers)
|
||||
hostnameChoices = validation.HideMyAssHostnameChoices(servers)
|
||||
case constants.Ipvanish:
|
||||
servers := allServers.GetIpvanish()
|
||||
countryChoices = constants.IpvanishCountryChoices(servers)
|
||||
cityChoices = constants.IpvanishCityChoices(servers)
|
||||
hostnameChoices = constants.IpvanishHostnameChoices(servers)
|
||||
countryChoices = validation.IpvanishCountryChoices(servers)
|
||||
cityChoices = validation.IpvanishCityChoices(servers)
|
||||
hostnameChoices = validation.IpvanishHostnameChoices(servers)
|
||||
case constants.Ivpn:
|
||||
servers := allServers.GetIvpn()
|
||||
countryChoices = constants.IvpnCountryChoices(servers)
|
||||
cityChoices = constants.IvpnCityChoices(servers)
|
||||
ispChoices = constants.IvpnISPChoices(servers)
|
||||
hostnameChoices = constants.IvpnHostnameChoices(servers)
|
||||
countryChoices = validation.IvpnCountryChoices(servers)
|
||||
cityChoices = validation.IvpnCityChoices(servers)
|
||||
ispChoices = validation.IvpnISPChoices(servers)
|
||||
hostnameChoices = validation.IvpnHostnameChoices(servers)
|
||||
case constants.Mullvad:
|
||||
servers := allServers.GetMullvad()
|
||||
countryChoices = constants.MullvadCountryChoices(servers)
|
||||
cityChoices = constants.MullvadCityChoices(servers)
|
||||
ispChoices = constants.MullvadISPChoices(servers)
|
||||
hostnameChoices = constants.MullvadHostnameChoices(servers)
|
||||
countryChoices = validation.MullvadCountryChoices(servers)
|
||||
cityChoices = validation.MullvadCityChoices(servers)
|
||||
ispChoices = validation.MullvadISPChoices(servers)
|
||||
hostnameChoices = validation.MullvadHostnameChoices(servers)
|
||||
case constants.Nordvpn:
|
||||
servers := allServers.GetNordvpn()
|
||||
regionChoices = constants.NordvpnRegionChoices(servers)
|
||||
hostnameChoices = constants.NordvpnHostnameChoices(servers)
|
||||
regionChoices = validation.NordvpnRegionChoices(servers)
|
||||
hostnameChoices = validation.NordvpnHostnameChoices(servers)
|
||||
case constants.Perfectprivacy:
|
||||
servers := allServers.GetPerfectprivacy()
|
||||
cityChoices = constants.PerfectprivacyCityChoices(servers)
|
||||
cityChoices = validation.PerfectprivacyCityChoices(servers)
|
||||
case constants.Privado:
|
||||
servers := allServers.GetPrivado()
|
||||
countryChoices = constants.PrivadoCountryChoices(servers)
|
||||
regionChoices = constants.PrivadoRegionChoices(servers)
|
||||
cityChoices = constants.PrivadoCityChoices(servers)
|
||||
hostnameChoices = constants.PrivadoHostnameChoices(servers)
|
||||
countryChoices = validation.PrivadoCountryChoices(servers)
|
||||
regionChoices = validation.PrivadoRegionChoices(servers)
|
||||
cityChoices = validation.PrivadoCityChoices(servers)
|
||||
hostnameChoices = validation.PrivadoHostnameChoices(servers)
|
||||
case constants.PrivateInternetAccess:
|
||||
servers := allServers.GetPia()
|
||||
regionChoices = constants.PIAGeoChoices(servers)
|
||||
hostnameChoices = constants.PIAHostnameChoices(servers)
|
||||
nameChoices = constants.PIANameChoices(servers)
|
||||
regionChoices = validation.PIAGeoChoices(servers)
|
||||
hostnameChoices = validation.PIAHostnameChoices(servers)
|
||||
nameChoices = validation.PIANameChoices(servers)
|
||||
case constants.Privatevpn:
|
||||
servers := allServers.GetPrivatevpn()
|
||||
countryChoices = constants.PrivatevpnCountryChoices(servers)
|
||||
cityChoices = constants.PrivatevpnCityChoices(servers)
|
||||
hostnameChoices = constants.PrivatevpnHostnameChoices(servers)
|
||||
countryChoices = validation.PrivatevpnCountryChoices(servers)
|
||||
cityChoices = validation.PrivatevpnCityChoices(servers)
|
||||
hostnameChoices = validation.PrivatevpnHostnameChoices(servers)
|
||||
case constants.Protonvpn:
|
||||
servers := allServers.GetProtonvpn()
|
||||
countryChoices = constants.ProtonvpnCountryChoices(servers)
|
||||
regionChoices = constants.ProtonvpnRegionChoices(servers)
|
||||
cityChoices = constants.ProtonvpnCityChoices(servers)
|
||||
nameChoices = constants.ProtonvpnNameChoices(servers)
|
||||
hostnameChoices = constants.ProtonvpnHostnameChoices(servers)
|
||||
countryChoices = validation.ProtonvpnCountryChoices(servers)
|
||||
regionChoices = validation.ProtonvpnRegionChoices(servers)
|
||||
cityChoices = validation.ProtonvpnCityChoices(servers)
|
||||
nameChoices = validation.ProtonvpnNameChoices(servers)
|
||||
hostnameChoices = validation.ProtonvpnHostnameChoices(servers)
|
||||
case constants.Purevpn:
|
||||
servers := allServers.GetPurevpn()
|
||||
countryChoices = constants.PurevpnCountryChoices(servers)
|
||||
regionChoices = constants.PurevpnRegionChoices(servers)
|
||||
cityChoices = constants.PurevpnCityChoices(servers)
|
||||
hostnameChoices = constants.PurevpnHostnameChoices(servers)
|
||||
countryChoices = validation.PurevpnCountryChoices(servers)
|
||||
regionChoices = validation.PurevpnRegionChoices(servers)
|
||||
cityChoices = validation.PurevpnCityChoices(servers)
|
||||
hostnameChoices = validation.PurevpnHostnameChoices(servers)
|
||||
case constants.Surfshark:
|
||||
servers := allServers.GetSurfshark()
|
||||
countryChoices = constants.SurfsharkCountryChoices(servers)
|
||||
cityChoices = constants.SurfsharkCityChoices(servers)
|
||||
hostnameChoices = constants.SurfsharkHostnameChoices(servers)
|
||||
regionChoices = constants.SurfsharkRegionChoices(servers)
|
||||
countryChoices = validation.SurfsharkCountryChoices(servers)
|
||||
cityChoices = validation.SurfsharkCityChoices(servers)
|
||||
hostnameChoices = validation.SurfsharkHostnameChoices(servers)
|
||||
regionChoices = validation.SurfsharkRegionChoices(servers)
|
||||
// TODO v4 remove
|
||||
regionChoices = append(regionChoices, constants.SurfsharkRetroLocChoices(servers)...)
|
||||
regionChoices = append(regionChoices, validation.SurfsharkRetroLocChoices()...)
|
||||
if err := helpers.AreAllOneOf(ss.Regions, regionChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
||||
}
|
||||
@@ -157,26 +158,26 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
|
||||
*ss = surfsharkRetroRegion(*ss)
|
||||
case constants.Torguard:
|
||||
servers := allServers.GetTorguard()
|
||||
countryChoices = constants.TorguardCountryChoices(servers)
|
||||
cityChoices = constants.TorguardCityChoices(servers)
|
||||
hostnameChoices = constants.TorguardHostnameChoices(servers)
|
||||
countryChoices = validation.TorguardCountryChoices(servers)
|
||||
cityChoices = validation.TorguardCityChoices(servers)
|
||||
hostnameChoices = validation.TorguardHostnameChoices(servers)
|
||||
case constants.VPNUnlimited:
|
||||
servers := allServers.GetVPNUnlimited()
|
||||
countryChoices = constants.VPNUnlimitedCountryChoices(servers)
|
||||
cityChoices = constants.VPNUnlimitedCityChoices(servers)
|
||||
hostnameChoices = constants.VPNUnlimitedHostnameChoices(servers)
|
||||
countryChoices = validation.VPNUnlimitedCountryChoices(servers)
|
||||
cityChoices = validation.VPNUnlimitedCityChoices(servers)
|
||||
hostnameChoices = validation.VPNUnlimitedHostnameChoices(servers)
|
||||
case constants.Vyprvpn:
|
||||
servers := allServers.GetVyprvpn()
|
||||
regionChoices = constants.VyprvpnRegionChoices(servers)
|
||||
regionChoices = validation.VyprvpnRegionChoices(servers)
|
||||
case constants.Wevpn:
|
||||
servers := allServers.GetWevpn()
|
||||
cityChoices = constants.WevpnCityChoices(servers)
|
||||
hostnameChoices = constants.WevpnHostnameChoices(servers)
|
||||
cityChoices = validation.WevpnCityChoices(servers)
|
||||
hostnameChoices = validation.WevpnHostnameChoices(servers)
|
||||
case constants.Windscribe:
|
||||
servers := allServers.GetWindscribe()
|
||||
regionChoices = constants.WindscribeRegionChoices(servers)
|
||||
cityChoices = constants.WindscribeCityChoices(servers)
|
||||
hostnameChoices = constants.WindscribeHostnameChoices(servers)
|
||||
regionChoices = validation.WindscribeRegionChoices(servers)
|
||||
cityChoices = validation.WindscribeCityChoices(servers)
|
||||
hostnameChoices = validation.WindscribeHostnameChoices(servers)
|
||||
default:
|
||||
return fmt.Errorf("%w: %s", ErrVPNProviderNameNotValid, vpnServiceProvider)
|
||||
}
|
||||
|
||||
21
internal/configuration/settings/validation/cyberghost.go
Normal file
21
internal/configuration/settings/validation/cyberghost.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func CyberghostCountryChoices(servers []models.CyberghostServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func CyberghostHostnameChoices(servers []models.CyberghostServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
29
internal/configuration/settings/validation/expressvpn.go
Normal file
29
internal/configuration/settings/validation/expressvpn.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func ExpressvpnCountriesChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ExpressvpnCityChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ExpressvpnHostnameChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
21
internal/configuration/settings/validation/fastestvpn.go
Normal file
21
internal/configuration/settings/validation/fastestvpn.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func FastestvpnCountriesChoices(servers []models.FastestvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func FastestvpnHostnameChoices(servers []models.FastestvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
23
internal/configuration/settings/validation/helpers.go
Normal file
23
internal/configuration/settings/validation/helpers.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package validation
|
||||
|
||||
import "sort"
|
||||
|
||||
func makeUnique(choices []string) (uniqueChoices []string) {
|
||||
seen := make(map[string]struct{}, len(choices))
|
||||
uniqueChoices = make([]string, 0, len(uniqueChoices))
|
||||
|
||||
for _, choice := range choices {
|
||||
if _, ok := seen[choice]; ok {
|
||||
continue
|
||||
}
|
||||
seen[choice] = struct{}{}
|
||||
|
||||
uniqueChoices = append(uniqueChoices, choice)
|
||||
}
|
||||
|
||||
sort.Slice(uniqueChoices, func(i, j int) bool {
|
||||
return uniqueChoices[i] < uniqueChoices[j]
|
||||
})
|
||||
|
||||
return uniqueChoices
|
||||
}
|
||||
37
internal/configuration/settings/validation/hidemyass.go
Normal file
37
internal/configuration/settings/validation/hidemyass.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func HideMyAssCountryChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssRegionChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssCityChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssHostnameChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
29
internal/configuration/settings/validation/ipvanish.go
Normal file
29
internal/configuration/settings/validation/ipvanish.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func IpvanishCountryChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IpvanishCityChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IpvanishHostnameChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
37
internal/configuration/settings/validation/ivpn.go
Normal file
37
internal/configuration/settings/validation/ivpn.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func IvpnCountryChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnCityChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnISPChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].ISP
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnHostnameChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
37
internal/configuration/settings/validation/mullvad.go
Normal file
37
internal/configuration/settings/validation/mullvad.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func MullvadCountryChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadCityChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadHostnameChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadISPChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].ISP
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
21
internal/configuration/settings/validation/nordvpn.go
Normal file
21
internal/configuration/settings/validation/nordvpn.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func NordvpnRegionChoices(servers []models.NordvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func NordvpnHostnameChoices(servers []models.NordvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
13
internal/configuration/settings/validation/perfectprivacy.go
Normal file
13
internal/configuration/settings/validation/perfectprivacy.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func PerfectprivacyCityChoices(servers []models.PerfectprivacyServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
29
internal/configuration/settings/validation/pia.go
Normal file
29
internal/configuration/settings/validation/pia.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func PIAGeoChoices(servers []models.PIAServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PIAHostnameChoices(servers []models.PIAServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PIANameChoices(servers []models.PIAServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].ServerName
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
35
internal/configuration/settings/validation/privado.go
Normal file
35
internal/configuration/settings/validation/privado.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func PrivadoCountryChoices(servers []models.PrivadoServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PrivadoRegionChoices(servers []models.PrivadoServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PrivadoCityChoices(servers []models.PrivadoServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PrivadoHostnameChoices(servers []models.PrivadoServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
27
internal/configuration/settings/validation/privatevpn.go
Normal file
27
internal/configuration/settings/validation/privatevpn.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func PrivatevpnCountryChoices(servers []models.PrivatevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PrivatevpnCityChoices(servers []models.PrivatevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PrivatevpnHostnameChoices(servers []models.PrivatevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
43
internal/configuration/settings/validation/protonvpn.go
Normal file
43
internal/configuration/settings/validation/protonvpn.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func ProtonvpnCountryChoices(servers []models.ProtonvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ProtonvpnRegionChoices(servers []models.ProtonvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ProtonvpnCityChoices(servers []models.ProtonvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ProtonvpnNameChoices(servers []models.ProtonvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Name
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ProtonvpnHostnameChoices(servers []models.ProtonvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
35
internal/configuration/settings/validation/purevpn.go
Normal file
35
internal/configuration/settings/validation/purevpn.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func PurevpnRegionChoices(servers []models.PurevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PurevpnCountryChoices(servers []models.PurevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PurevpnCityChoices(servers []models.PurevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func PurevpnHostnameChoices(servers []models.PurevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
60
internal/configuration/settings/validation/surfshark.go
Normal file
60
internal/configuration/settings/validation/surfshark.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func SurfsharkRegionChoices(servers []models.SurfsharkServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func SurfsharkCountryChoices(servers []models.SurfsharkServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func SurfsharkCityChoices(servers []models.SurfsharkServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func SurfsharkHostnameChoices(servers []models.SurfsharkServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
// TODO remove in v4.
|
||||
func SurfsharkRetroLocChoices() (choices []string) {
|
||||
locationData := constants.SurfsharkLocationData()
|
||||
choices = make([]string, 0, len(locationData))
|
||||
seen := make(map[string]struct{}, len(locationData))
|
||||
for _, data := range locationData {
|
||||
if _, ok := seen[data.RetroLoc]; ok {
|
||||
continue
|
||||
}
|
||||
seen[data.RetroLoc] = struct{}{}
|
||||
choices = append(choices, data.RetroLoc)
|
||||
}
|
||||
|
||||
sort.Slice(choices, func(i, j int) bool {
|
||||
return choices[i] < choices[j]
|
||||
})
|
||||
|
||||
return choices
|
||||
}
|
||||
29
internal/configuration/settings/validation/torguard.go
Normal file
29
internal/configuration/settings/validation/torguard.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func TorguardCountryChoices(servers []models.TorguardServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func TorguardCityChoices(servers []models.TorguardServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func TorguardHostnameChoices(servers []models.TorguardServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
29
internal/configuration/settings/validation/vpnunlimited.go
Normal file
29
internal/configuration/settings/validation/vpnunlimited.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func VPNUnlimitedCountryChoices(servers []models.VPNUnlimitedServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func VPNUnlimitedCityChoices(servers []models.VPNUnlimitedServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func VPNUnlimitedHostnameChoices(servers []models.VPNUnlimitedServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
13
internal/configuration/settings/validation/vyprvpn.go
Normal file
13
internal/configuration/settings/validation/vyprvpn.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func VyprvpnRegionChoices(servers []models.VyprvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
19
internal/configuration/settings/validation/wevpn.go
Normal file
19
internal/configuration/settings/validation/wevpn.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func WevpnCityChoices(servers []models.WevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func WevpnHostnameChoices(servers []models.WevpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
27
internal/configuration/settings/validation/windscribe.go
Normal file
27
internal/configuration/settings/validation/windscribe.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package validation
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
|
||||
func WindscribeRegionChoices(servers []models.WindscribeServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func WindscribeCityChoices(servers []models.WindscribeServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func WindscribeHostnameChoices(servers []models.WindscribeServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
Reference in New Issue
Block a user