Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
Showing
72 changed files
with
789 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Oops, something went wrong.