diff --git a/internal/configuration/settings/helpers/messages.go b/internal/configuration/settings/helpers/messages.go deleted file mode 100644 index 1442b979..00000000 --- a/internal/configuration/settings/helpers/messages.go +++ /dev/null @@ -1,29 +0,0 @@ -package helpers - -import ( - "fmt" - "strings" -) - -func ChoicesOrString(choices []string) string { - return strings.Join( - choices[:len(choices)-1], ", ") + - " or " + choices[len(choices)-1] -} - -func PortChoicesOrString(ports []uint16) (s string) { - switch len(ports) { - case 0: - return "there is no allowed port" - case 1: - return "allowed port is " + fmt.Sprint(ports[0]) - } - - s = "allowed ports are " - portStrings := make([]string, len(ports)) - for i := range ports { - portStrings[i] = fmt.Sprint(ports[i]) - } - s += ChoicesOrString(portStrings) - return s -} diff --git a/internal/configuration/settings/wireguardselection.go b/internal/configuration/settings/wireguardselection.go index b153bd73..04b8c89d 100644 --- a/internal/configuration/settings/wireguardselection.go +++ b/internal/configuration/settings/wireguardselection.go @@ -4,9 +4,9 @@ import ( "fmt" "net/netip" - "github.com/qdm12/gluetun/internal/configuration/settings/helpers" "github.com/qdm12/gluetun/internal/constants/providers" "github.com/qdm12/gosettings" + "github.com/qdm12/gosettings/validate" "github.com/qdm12/gotree" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -77,12 +77,12 @@ func (w WireguardSelection) validate(vpnProvider string) (err error) { allowed = []uint16{53, 80, 123, 443, 1194, 65142} } - if helpers.IsOneOf(*w.EndpointPort, allowed...) { + err = validate.IsOneOf(*w.EndpointPort, allowed...) + if err == nil { break } - return fmt.Errorf("%w: %d for VPN service provider %s; %s", - ErrWireguardEndpointPortNotAllowed, w.EndpointPort, vpnProvider, - helpers.PortChoicesOrString(allowed)) + return fmt.Errorf("%w: for VPN service provider %s: %w", + ErrWireguardEndpointPortNotAllowed, vpnProvider, err) default: // Providers not supporting Wireguard }