Maint: common GetPort for OpenVPN+Wireguard providers
This commit is contained in:
27
internal/provider/utils/port.go
Normal file
27
internal/provider/utils/port.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func GetPort(selection configuration.ServerSelection,
|
||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
||||
switch selection.VPN {
|
||||
case constants.Wireguard:
|
||||
customPort := selection.Wireguard.CustomPort
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
}
|
||||
return defaultWireguard
|
||||
default: // OpenVPN
|
||||
customPort := selection.OpenVPN.CustomPort
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
}
|
||||
if selection.OpenVPN.TCP {
|
||||
return defaultOpenVPNTCP
|
||||
}
|
||||
return defaultOpenVPNUDP
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user