Make all variables behave like server filters

This commit is contained in:
Quentin McGaw
2020-07-23 01:48:18 +00:00
parent fec1249293
commit 0ce129b63d
8 changed files with 23 additions and 23 deletions

View File

@@ -10,14 +10,15 @@ import (
// GetCyberghostGroup obtains the server group for the Cyberghost server from the
// environment variable CYBERGHOST_GROUP
func (p *reader) GetCyberghostGroup() (group string, err error) {
s, err := p.envParams.GetValueIfInside("CYBERGHOST_GROUP", constants.CyberghostGroupChoices())
s, err := p.envParams.GetValueIfInside("CYBERGHOST_GROUP", constants.CyberghostGroupChoices(), libparams.Default("Premium UDP Europe"))
return s, err
}
// GetCyberghostRegion obtains the country name for the Cyberghost server from the
// environment variable REGION
func (p *reader) GetCyberghostRegion() (region string, err error) {
s, err := p.envParams.GetValueIfInside("REGION", constants.CyberghostRegionChoices())
choices := append(constants.CyberghostRegionChoices(), "")
s, err := p.envParams.GetValueIfInside("REGION", choices)
return s, err
}

View File

@@ -8,7 +8,8 @@ import (
// GetNordvpnRegion obtains the region (country) for the NordVPN server from the
// environment variable REGION
func (r *reader) GetNordvpnRegion() (region string, err error) {
return r.envParams.GetValueIfInside("REGION", constants.NordvpnRegionChoices())
choices := append(constants.NordvpnRegionChoices(), "")
return r.envParams.GetValueIfInside("REGION", choices)
}
// GetNordvpnRegion obtains the server number (optional) for the NordVPN server from the

View File

@@ -2,7 +2,6 @@ package params
import (
"fmt"
"math/rand"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/constants"
@@ -60,9 +59,5 @@ func (r *reader) GetPIAEncryptionPreset() (preset string, err error) {
// environment variable REGION
func (r *reader) GetPIARegion() (region string, err error) {
choices := append(constants.PIAGeoChoices(), "")
s, err := r.envParams.GetValueIfInside("REGION", choices)
if len(s) == 0 { // Suggestion by @rorph https://github.com/rorph
s = choices[rand.Int()%len(choices)] //nolint:gosec
}
return s, err
return r.envParams.GetValueIfInside("REGION", choices)
}

View File

@@ -7,6 +7,6 @@ import (
// GetSurfsharkRegion obtains the region for the Surfshark server from the
// environment variable REGION
func (r *reader) GetSurfsharkRegion() (region string, err error) {
s, err := r.envParams.GetValueIfInside("REGION", constants.SurfsharkRegionChoices())
return s, err
choices := append(constants.SurfsharkRegionChoices(), "")
return r.envParams.GetValueIfInside("REGION", choices)
}

View File

@@ -7,5 +7,6 @@ import (
// GetVyprvpnRegion obtains the region for the Vyprvpn server from the
// environment variable REGION
func (r *reader) GetVyprvpnRegion() (region string, err error) {
return r.envParams.GetValueIfInside("REGION", constants.VyprvpnRegionChoices())
choices := append(constants.VyprvpnRegionChoices(), "")
return r.envParams.GetValueIfInside("REGION", choices)
}

View File

@@ -11,8 +11,8 @@ import (
// GetWindscribeRegion obtains the region for the Windscribe server from the
// environment variable REGION
func (r *reader) GetWindscribeRegion() (region string, err error) {
s, err := r.envParams.GetValueIfInside("REGION", constants.WindscribeRegionChoices())
return s, err
choices := append(constants.WindscribeRegionChoices(), "")
return r.envParams.GetValueIfInside("REGION", choices)
}
// GetMullvadPort obtains the port to reach the Mullvad server on from the