chore: use gofumpt for code formatting
This commit is contained in:
@@ -16,7 +16,8 @@ type ConnectionDefaults struct {
|
||||
}
|
||||
|
||||
func NewConnectionDefaults(openvpnTCPPort, openvpnUDPPort,
|
||||
wireguardPort uint16) ConnectionDefaults {
|
||||
wireguardPort uint16,
|
||||
) ConnectionDefaults {
|
||||
return ConnectionDefaults{
|
||||
OpenVPNTCPPort: openvpnTCPPort,
|
||||
OpenVPNUDPPort: openvpnUDPPort,
|
||||
@@ -35,7 +36,8 @@ func GetConnection(provider string,
|
||||
defaults ConnectionDefaults,
|
||||
ipv6Supported bool,
|
||||
randSource rand.Source) (
|
||||
connection models.Connection, err error) {
|
||||
connection models.Connection, err error,
|
||||
) {
|
||||
servers, err := storage.FilterServers(provider, selection)
|
||||
if err != nil {
|
||||
return connection, fmt.Errorf("filtering servers: %w", err)
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func filterServers(servers []models.Server,
|
||||
selection settings.ServerSelection) (filtered []models.Server) {
|
||||
selection settings.ServerSelection,
|
||||
) (filtered []models.Server) {
|
||||
for _, server := range servers {
|
||||
if filterServer(server, selection) {
|
||||
continue
|
||||
@@ -22,7 +23,8 @@ func filterServers(servers []models.Server,
|
||||
}
|
||||
|
||||
func filterServer(server models.Server,
|
||||
selection settings.ServerSelection) (filtered bool) {
|
||||
selection settings.ServerSelection,
|
||||
) (filtered bool) {
|
||||
// Note each condition is split to make sure
|
||||
// we have full testing coverage.
|
||||
if server.VPN != selection.VPN {
|
||||
|
||||
@@ -21,6 +21,7 @@ func NewNoFetcher(providerName string) *NoFetcher {
|
||||
var ErrFetcherNotSupported = errors.New("fetching of servers is not supported")
|
||||
|
||||
func (n *NoFetcher) FetchServers(context.Context, int) (
|
||||
servers []models.Server, err error) {
|
||||
servers []models.Server, err error,
|
||||
) {
|
||||
return nil, fmt.Errorf("%w: for %s", ErrFetcherNotSupported, n.providerName)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ type OpenVPNProviderSettings struct {
|
||||
//nolint:gocognit,gocyclo
|
||||
func OpenVPNConfig(provider OpenVPNProviderSettings,
|
||||
connection models.Connection,
|
||||
settings settings.OpenVPN, ipv6Supported bool) []string {
|
||||
settings settings.OpenVPN, ipv6Supported bool,
|
||||
) []string {
|
||||
var lines openvpnConfigLines
|
||||
lines.add("client")
|
||||
lines.add("nobind")
|
||||
@@ -254,7 +255,8 @@ func defaultUint16(value, defaultValue uint16) uint16 {
|
||||
}
|
||||
|
||||
func defaultStringSlice(value, defaultValue []string) (
|
||||
result []string) {
|
||||
result []string,
|
||||
) {
|
||||
if len(value) > 0 {
|
||||
result = make([]string, len(value))
|
||||
copy(result, value)
|
||||
|
||||
@@ -20,7 +20,8 @@ var ErrNoConnectionToPickFrom = errors.New("no connection to pick from")
|
||||
// and sets the target IP address as the IP if this one is set.
|
||||
func pickConnection(connections []models.Connection,
|
||||
selection settings.ServerSelection, randSource rand.Source) (
|
||||
connection models.Connection, err error) {
|
||||
connection models.Connection, err error,
|
||||
) {
|
||||
if len(connections) == 0 {
|
||||
return connection, ErrNoConnectionToPickFrom
|
||||
}
|
||||
@@ -41,14 +42,16 @@ func pickConnection(connections []models.Connection,
|
||||
}
|
||||
|
||||
func pickRandomConnection(connections []models.Connection,
|
||||
source rand.Source) models.Connection {
|
||||
source rand.Source,
|
||||
) models.Connection {
|
||||
return connections[rand.New(source).Intn(len(connections))] //nolint:gosec
|
||||
}
|
||||
|
||||
var errTargetIPNotFound = errors.New("target IP address not found")
|
||||
|
||||
func getTargetIPConnection(connections []models.Connection,
|
||||
targetIP netip.Addr) (connection models.Connection, err error) {
|
||||
targetIP netip.Addr,
|
||||
) (connection models.Connection, err error) {
|
||||
for _, connection := range connections {
|
||||
if targetIP == connection.IP {
|
||||
return connection, nil
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func getPort(selection settings.ServerSelection,
|
||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16,
|
||||
) (port uint16) {
|
||||
switch selection.VPN {
|
||||
case vpn.Wireguard:
|
||||
customPort := *selection.Wireguard.EndpointPort
|
||||
|
||||
@@ -14,7 +14,8 @@ func getProtocol(selection settings.ServerSelection) (protocol string) {
|
||||
}
|
||||
|
||||
func filterByProtocol(selection settings.ServerSelection,
|
||||
serverTCP, serverUDP bool) (filtered bool) {
|
||||
serverTCP, serverUDP bool,
|
||||
) (filtered bool) {
|
||||
switch selection.VPN {
|
||||
case vpn.Wireguard:
|
||||
return !serverUDP
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func BuildWireguardSettings(connection models.Connection,
|
||||
userSettings settings.Wireguard, ipv6Supported bool) (settings wireguard.Settings) {
|
||||
userSettings settings.Wireguard, ipv6Supported bool,
|
||||
) (settings wireguard.Settings) {
|
||||
settings.PrivateKey = *userSettings.PrivateKey
|
||||
settings.PublicKey = connection.PubKey
|
||||
settings.PreSharedKey = *userSettings.PreSharedKey
|
||||
|
||||
Reference in New Issue
Block a user