chore: simplify provider GetConnection

This commit is contained in:
Quentin McGaw
2022-04-19 14:28:57 +00:00
parent 306d8494d6
commit 0c0f1663b1
36 changed files with 243 additions and 707 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn/extract"
"github.com/qdm12/gluetun/internal/provider/utils"
)
var (
@@ -37,23 +36,21 @@ func getOpenVPNConnection(extractor extract.Interface,
return connection, fmt.Errorf("cannot extract connection: %w", err)
}
connection.Port = getPort(connection.Port, selection)
customPort := *selection.OpenVPN.CustomPort
if customPort > 0 {
connection.Port = customPort
}
return connection, nil
}
func getWireguardConnection(selection settings.ServerSelection) (
connection models.Connection) {
port := getPort(*selection.Wireguard.EndpointPort, selection)
return models.Connection{
Type: vpn.Wireguard,
IP: selection.Wireguard.EndpointIP,
Port: port,
Port: *selection.Wireguard.EndpointPort,
Protocol: constants.UDP,
PubKey: selection.Wireguard.PublicKey,
}
}
// Port found is overridden by custom port set with `VPN_ENDPOINT_PORT`.
func getPort(foundPort uint16, selection settings.ServerSelection) (port uint16) {
return utils.GetPort(selection, foundPort, foundPort, foundPort)
}