From 76a4bb5dc3e2ca19c92ec8c8d396de9f35b7d79f Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 11 Oct 2024 19:20:48 +0000 Subject: [PATCH] chore: use gofumpt for code formatting --- .devcontainer/devcontainer.json | 3 +- .golangci.yml | 1 + cmd/gluetun/main.go | 15 +++++---- internal/alpine/users.go | 6 ++-- internal/cli/formatservers.go | 5 +-- internal/cli/openvpnconfig.go | 3 +- internal/command/start.go | 9 +++-- .../configuration/settings/dnsblacklist.go | 10 +++--- internal/configuration/settings/dot.go | 4 +-- .../configuration/settings/nordvpn_retro.go | 3 +- internal/configuration/settings/openvpn.go | 9 +++-- internal/configuration/settings/publicip.go | 3 +- .../configuration/settings/serverselection.go | 15 ++++++--- internal/configuration/settings/settings.go | 6 ++-- .../configuration/settings/surfshark_retro.go | 3 +- .../configuration/sources/files/wireguard.go | 18 ++++------ .../sources/files/wireguard_test.go | 2 +- .../sources/secrets/reader_test.go | 6 ++-- internal/dns/loop.go | 3 +- internal/dns/settings.go | 6 ++-- internal/dns/state/settings.go | 3 +- internal/dns/state/state.go | 3 +- internal/dns/status.go | 3 +- internal/firewall/delete.go | 12 ++++--- internal/firewall/firewall.go | 3 +- internal/firewall/ip6tables.go | 3 +- internal/firewall/iptables.go | 15 ++++++--- internal/firewall/list.go | 24 ++++---------- internal/firewall/parse.go | 4 +-- internal/firewall/redirect.go | 6 ++-- internal/firewall/support.go | 6 ++-- internal/firewall/support_test.go | 6 ++-- internal/firewall/vpn.go | 3 +- internal/healthcheck/client.go | 4 +-- internal/healthcheck/server.go | 3 +- internal/httpproxy/handler.go | 6 ++-- internal/httpproxy/server.go | 3 +- internal/httpproxy/settings.go | 3 +- internal/httpproxy/state/settings.go | 3 +- internal/httpproxy/state/state.go | 3 +- internal/httpproxy/status.go | 3 +- internal/loopstate/apply.go | 3 +- internal/loopstate/state.go | 3 +- internal/mod/info.go | 8 ++--- internal/models/markdown.go | 22 ++++++++----- internal/models/servers.go | 4 +-- internal/natpmp/checks.go | 7 ++-- internal/natpmp/externaladdress.go | 3 +- internal/natpmp/externaladdress_test.go | 3 +- internal/natpmp/helpers_test.go | 3 +- internal/natpmp/portmapping.go | 3 +- internal/natpmp/portmapping_test.go | 7 ++-- internal/natpmp/rpc.go | 3 +- internal/netlink/address.go | 3 +- internal/netlink/address_unspecified.go | 3 +- internal/netlink/route_unspecified.go | 3 +- internal/openvpn/auth.go | 2 +- internal/openvpn/config.go | 2 +- internal/openvpn/extract/data.go | 3 +- internal/openvpn/extract/extract.go | 17 +++++----- internal/openvpn/extract/pem.go | 4 +-- internal/openvpn/extract/read.go | 3 +- internal/openvpn/logs_test.go | 21 ++++++++---- internal/openvpn/openvpn.go | 3 +- internal/openvpn/pkcs8/algorithms.go | 15 ++++----- internal/openvpn/pkcs8/upgrade.go | 4 +-- internal/openvpn/run.go | 3 +- internal/openvpn/start.go | 3 +- internal/openvpn/stream.go | 3 +- internal/portforward/loop.go | 6 ++-- internal/portforward/service/fs.go | 2 +- internal/portforward/service/service.go | 3 +- internal/portforward/service/start.go | 3 +- internal/portforward/settings.go | 3 +- internal/provider/airvpn/connection.go | 3 +- internal/provider/airvpn/openvpnconf.go | 6 ++-- internal/provider/airvpn/provider.go | 3 +- internal/provider/airvpn/updater/api.go | 3 +- internal/provider/airvpn/updater/servers.go | 3 +- internal/provider/common/portforward.go | 4 +-- internal/provider/custom/connection.go | 13 ++++---- internal/provider/custom/openvpnconf.go | 6 ++-- internal/provider/cyberghost/connection.go | 3 +- internal/provider/cyberghost/openvpnconf.go | 3 +- internal/provider/cyberghost/provider.go | 3 +- .../provider/cyberghost/updater/servers.go | 3 +- internal/provider/example/connection.go | 3 +- internal/provider/example/openvpnconf.go | 3 +- internal/provider/example/provider.go | 3 +- internal/provider/example/updater/api.go | 7 ++-- internal/provider/example/updater/servers.go | 3 +- internal/provider/example/updater/updater.go | 3 +- internal/provider/expressvpn/connection.go | 3 +- internal/provider/expressvpn/openvpnconf.go | 3 +- internal/provider/expressvpn/provider.go | 3 +- .../provider/expressvpn/updater/servers.go | 3 +- .../provider/expressvpn/updater/updater.go | 3 +- internal/provider/fastestvpn/connection.go | 3 +- internal/provider/fastestvpn/openvpnconf.go | 3 +- internal/provider/fastestvpn/provider.go | 3 +- internal/provider/fastestvpn/updater/api.go | 7 ++-- .../provider/fastestvpn/updater/servers.go | 3 +- .../provider/fastestvpn/updater/updater.go | 3 +- internal/provider/giganews/connection.go | 3 +- internal/provider/giganews/openvpnconf.go | 3 +- internal/provider/giganews/provider.go | 3 +- internal/provider/giganews/updater/servers.go | 3 +- internal/provider/giganews/updater/updater.go | 3 +- internal/provider/hidemyass/connection.go | 3 +- internal/provider/hidemyass/openvpnconf.go | 3 +- internal/provider/hidemyass/provider.go | 3 +- internal/provider/hidemyass/updater/hosts.go | 3 +- .../provider/hidemyass/updater/hosttourl.go | 6 ++-- internal/provider/hidemyass/updater/index.go | 3 +- .../provider/hidemyass/updater/servers.go | 3 +- .../provider/hidemyass/updater/updater.go | 3 +- internal/provider/ipvanish/connection.go | 3 +- internal/provider/ipvanish/openvpnconf.go | 3 +- internal/provider/ipvanish/provider.go | 3 +- .../provider/ipvanish/updater/filename.go | 3 +- internal/provider/ipvanish/updater/servers.go | 3 +- internal/provider/ipvanish/updater/updater.go | 3 +- internal/provider/ivpn/connection.go | 3 +- internal/provider/ivpn/openvpnconf.go | 3 +- internal/provider/ivpn/provider.go | 3 +- internal/provider/ivpn/updater/api.go | 7 ++-- internal/provider/ivpn/updater/servers.go | 3 +- .../provider/ivpn/updater/servers_test.go | 18 ++++++---- internal/provider/ivpn/updater/updater.go | 3 +- internal/provider/mullvad/connection.go | 3 +- internal/provider/mullvad/openvpnconf.go | 3 +- internal/provider/mullvad/provider.go | 3 +- internal/provider/mullvad/updater/servers.go | 3 +- internal/provider/nordvpn/connection.go | 3 +- internal/provider/nordvpn/openvpnconf.go | 3 +- internal/provider/nordvpn/provider.go | 3 +- internal/provider/nordvpn/updater/api.go | 7 ++-- internal/provider/nordvpn/updater/models.go | 3 +- internal/provider/nordvpn/updater/servers.go | 10 +++--- .../provider/perfectprivacy/connection.go | 3 +- .../provider/perfectprivacy/openvpnconf.go | 3 +- .../provider/perfectprivacy/portforward.go | 6 ++-- internal/provider/perfectprivacy/provider.go | 3 +- .../perfectprivacy/updater/servers.go | 6 ++-- internal/provider/privado/connection.go | 3 +- internal/provider/privado/openvpnconf.go | 3 +- internal/provider/privado/provider.go | 3 +- internal/provider/privado/updater/servers.go | 3 +- internal/provider/privado/updater/updater.go | 3 +- .../privateinternetaccess/connection.go | 3 +- .../privateinternetaccess/openvpnconf.go | 3 +- .../privateinternetaccess/portforward.go | 33 +++++++++---------- .../privateinternetaccess/provider.go | 3 +- .../privateinternetaccess/updater/api.go | 7 ++-- .../updater/hosttoserver.go | 3 +- .../privateinternetaccess/updater/servers.go | 3 +- internal/provider/privatevpn/connection.go | 3 +- internal/provider/privatevpn/openvpnconf.go | 3 +- internal/provider/privatevpn/portforward.go | 14 ++++---- internal/provider/privatevpn/provider.go | 3 +- .../provider/privatevpn/updater/countries.go | 3 +- .../provider/privatevpn/updater/filename.go | 4 +-- .../provider/privatevpn/updater/servers.go | 3 +- .../provider/privatevpn/updater/updater.go | 3 +- internal/provider/protonvpn/connection.go | 3 +- internal/provider/protonvpn/openvpnconf.go | 3 +- internal/provider/protonvpn/portforward.go | 28 ++++++++-------- internal/provider/protonvpn/provider.go | 3 +- internal/provider/protonvpn/updater/api.go | 7 ++-- .../provider/protonvpn/updater/countries.go | 3 +- .../provider/protonvpn/updater/iptoserver.go | 3 +- .../provider/protonvpn/updater/servers.go | 3 +- internal/provider/providers.go | 3 +- internal/provider/purevpn/connection.go | 3 +- internal/provider/purevpn/openvpnconf.go | 3 +- internal/provider/purevpn/provider.go | 3 +- internal/provider/purevpn/updater/servers.go | 3 +- internal/provider/purevpn/updater/updater.go | 3 +- internal/provider/slickvpn/connection.go | 3 +- internal/provider/slickvpn/openvpnconf.go | 3 +- internal/provider/slickvpn/provider.go | 3 +- internal/provider/slickvpn/updater/servers.go | 3 +- internal/provider/slickvpn/updater/updater.go | 3 +- internal/provider/slickvpn/updater/website.go | 7 ++-- internal/provider/surfshark/connection.go | 3 +- internal/provider/surfshark/openvpnconf.go | 3 +- internal/provider/surfshark/provider.go | 3 +- internal/provider/surfshark/updater/api.go | 10 +++--- .../surfshark/updater/hosttoserver.go | 6 ++-- .../provider/surfshark/updater/location.go | 10 +++--- .../provider/surfshark/updater/servers.go | 3 +- .../provider/surfshark/updater/updater.go | 3 +- internal/provider/surfshark/updater/zip.go | 3 +- internal/provider/torguard/connection.go | 3 +- internal/provider/torguard/openvpnconf.go | 3 +- internal/provider/torguard/provider.go | 3 +- .../provider/torguard/updater/hosttoserver.go | 3 +- internal/provider/torguard/updater/servers.go | 6 ++-- internal/provider/torguard/updater/updater.go | 3 +- internal/provider/utils/connection.go | 6 ++-- internal/provider/utils/filtering.go | 6 ++-- internal/provider/utils/nofetcher.go | 3 +- internal/provider/utils/openvpn.go | 6 ++-- internal/provider/utils/pick.go | 9 +++-- internal/provider/utils/port.go | 3 +- internal/provider/utils/protocol.go | 3 +- internal/provider/utils/wireguard.go | 3 +- internal/provider/vpnsecure/connection.go | 3 +- internal/provider/vpnsecure/openvpnconf.go | 3 +- internal/provider/vpnsecure/provider.go | 3 +- .../provider/vpnsecure/updater/servers.go | 3 +- .../provider/vpnsecure/updater/updater.go | 3 +- .../provider/vpnsecure/updater/website.go | 16 +++++---- internal/provider/vpnunlimited/connection.go | 3 +- internal/provider/vpnunlimited/openvpnconf.go | 3 +- internal/provider/vpnunlimited/provider.go | 3 +- .../provider/vpnunlimited/updater/servers.go | 3 +- .../provider/vpnunlimited/updater/updater.go | 3 +- internal/provider/vyprvpn/connection.go | 3 +- internal/provider/vyprvpn/openvpnconf.go | 3 +- internal/provider/vyprvpn/provider.go | 3 +- internal/provider/vyprvpn/updater/servers.go | 3 +- internal/provider/vyprvpn/updater/updater.go | 3 +- internal/provider/wevpn/connection.go | 3 +- internal/provider/wevpn/openvpnconf.go | 3 +- internal/provider/wevpn/provider.go | 3 +- internal/provider/wevpn/updater/servers.go | 3 +- internal/provider/windscribe/connection.go | 3 +- internal/provider/windscribe/openvpnconf.go | 3 +- internal/provider/windscribe/provider.go | 3 +- internal/provider/windscribe/updater/api.go | 7 ++-- .../provider/windscribe/updater/servers.go | 7 ++-- internal/publicip/api/api.go | 7 ++-- internal/publicip/api/cloudflare.go | 3 +- internal/publicip/api/ifconfigco.go | 3 +- internal/publicip/api/ip2location.go | 3 +- internal/publicip/api/ipinfo.go | 3 +- internal/publicip/api/multi.go | 3 +- internal/publicip/fs.go | 2 +- internal/publicip/loop.go | 6 ++-- internal/routing/default.go | 4 +-- internal/routing/errors.go | 4 +-- internal/routing/ip.go | 4 +-- internal/routing/outbound.go | 9 +++-- internal/routing/routes.go | 6 ++-- internal/routing/rules.go | 3 +- internal/routing/rules_test.go | 3 +- internal/server/dns.go | 3 +- internal/server/handlerv0.go | 3 +- internal/server/handlerv1.go | 3 +- .../middlewares/auth/configfile_test.go | 2 +- .../server/middlewares/auth/lookup_test.go | 3 +- .../server/middlewares/auth/middleware.go | 3 +- internal/server/middlewares/log/middleware.go | 3 +- internal/server/openvpn.go | 3 +- internal/server/server.go | 3 +- internal/server/updater.go | 3 +- internal/server/vpn.go | 3 +- internal/shadowsocks/state.go | 6 ++-- internal/storage/filter.go | 9 +++-- internal/storage/flush.go | 2 +- internal/storage/merge.go | 3 +- internal/storage/read.go | 9 +++-- internal/tun/create.go | 2 +- internal/updater/html/fetch.go | 3 +- internal/updater/html/match.go | 6 ++-- internal/updater/loop/loop.go | 3 +- internal/updater/openvpn/fetch.go | 6 ++-- internal/updater/openvpn/multifetch.go | 3 +- internal/updater/providers.go | 3 +- internal/updater/resolver/parallel.go | 6 ++-- internal/updater/resolver/repeat.go | 6 ++-- internal/updater/unzip/fetch.go | 7 ++-- internal/updater/updater.go | 6 ++-- internal/version/version.go | 3 +- internal/vpn/helpers.go | 3 +- internal/vpn/loop.go | 3 +- internal/vpn/openvpn.go | 3 +- internal/vpn/portforward.go | 6 ++-- internal/vpn/settings.go | 3 +- internal/vpn/state/vpn.go | 3 +- internal/vpn/status.go | 3 +- internal/vpn/wireguard.go | 3 +- internal/wireguard/address.go | 3 +- internal/wireguard/cleanup.go | 3 +- internal/wireguard/constructor.go | 3 +- internal/wireguard/route.go | 6 ++-- internal/wireguard/rule.go | 3 +- internal/wireguard/run.go | 9 +++-- 289 files changed, 784 insertions(+), 548 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0b85f17e..18c16889 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -81,7 +81,8 @@ }, "gopls": { "usePlaceholders": false, - "staticcheck": true + "staticcheck": true, + "formatting.gofumpt": true, }, "go.lintTool": "golangci-lint", "go.lintOnSave": "package", diff --git a/.golangci.yml b/.golangci.yml index a11e549e..e7d933f4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -52,6 +52,7 @@ linters: - gocritic - gocyclo - godot + - gofumpt - goheader - goimports - gomoddirectives diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index 1d965976..ad8f309e 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -140,15 +140,14 @@ func main() { } } -var ( - errCommandUnknown = errors.New("command is unknown") -) +var errCommandUnknown = errors.New("command is unknown") //nolint:gocognit,gocyclo,maintidx func _main(ctx context.Context, buildInfo models.BuildInformation, args []string, logger log.LoggerInterface, reader *reader.Reader, tun Tun, netLinker netLinker, cmder RunStarter, - cli clier) error { + cli clier, +) error { if len(args) > 1 { // cli operation switch args[1] { case "healthcheck": @@ -288,7 +287,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation, logger.Warn(warning) } - const permission = fs.FileMode(0644) + const permission = fs.FileMode(0o644) err = os.MkdirAll("/tmp/gluetun", permission) if err != nil { return err @@ -366,7 +365,8 @@ func _main(ctx context.Context, buildInfo models.BuildInformation, } defaultGroupOptions := []group.Option{ group.OptionTimeout(defaultShutdownTimeout), - group.OptionOnSuccess(defaultShutdownOnSuccess)} + group.OptionOnSuccess(defaultShutdownOnSuccess), + } controlGroupHandler := goshutdown.NewGroupHandler("control", defaultGroupOptions...) tickersGroupHandler := goshutdown.NewGroupHandler("tickers", defaultGroupOptions...) @@ -532,7 +532,8 @@ type infoer interface { } func printVersions(ctx context.Context, logger infoer, - elements []printVersionElement) (err error) { + elements []printVersionElement, +) (err error) { const timeout = 5 * time.Second ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() diff --git a/internal/alpine/users.go b/internal/alpine/users.go index fa02db34..537974e3 100644 --- a/internal/alpine/users.go +++ b/internal/alpine/users.go @@ -9,9 +9,7 @@ import ( "strconv" ) -var ( - ErrUserAlreadyExists = errors.New("user already exists") -) +var ErrUserAlreadyExists = errors.New("user already exists") // CreateUser creates a user in Alpine with the given UID. func (a *Alpine) CreateUser(username string, uid int) (createdUsername string, err error) { @@ -40,7 +38,7 @@ func (a *Alpine) CreateUser(username string, uid int) (createdUsername string, e ErrUserAlreadyExists, username, u.Uid, uid) } - const permission = fs.FileMode(0644) + const permission = fs.FileMode(0o644) file, err := os.OpenFile(a.passwdPath, os.O_APPEND|os.O_WRONLY, permission) if err != nil { return "", err diff --git a/internal/cli/formatservers.go b/internal/cli/formatservers.go index 3f6121a3..254c0451 100644 --- a/internal/cli/formatservers.go +++ b/internal/cli/formatservers.go @@ -22,7 +22,8 @@ var ( ) func addProviderFlag(flagSet *flag.FlagSet, providerToFormat map[string]*bool, - provider string, titleCaser cases.Caser) { + provider string, titleCaser cases.Caser, +) { boolPtr, ok := providerToFormat[provider] if !ok { panic(fmt.Sprintf("unknown provider in format map: %s", provider)) @@ -91,7 +92,7 @@ func (c *CLI) FormatServers(args []string) error { } output = filepath.Clean(output) - const permission = fs.FileMode(0644) + const permission = fs.FileMode(0o644) file, err := os.OpenFile(output, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, permission) if err != nil { return fmt.Errorf("opening output file: %w", err) diff --git a/internal/cli/openvpnconfig.go b/internal/cli/openvpnconfig.go index 4b509061..aacfa1b8 100644 --- a/internal/cli/openvpnconfig.go +++ b/internal/cli/openvpnconfig.go @@ -42,7 +42,8 @@ type IPv6Checker interface { } func (c *CLI) OpenvpnConfig(logger OpenvpnConfigLogger, reader *reader.Reader, - ipv6Checker IPv6Checker) error { + ipv6Checker IPv6Checker, +) error { storage, err := storage.New(logger, constants.ServersData) if err != nil { return err diff --git a/internal/command/start.go b/internal/command/start.go index 9b987039..523b7073 100644 --- a/internal/command/start.go +++ b/internal/command/start.go @@ -13,12 +13,14 @@ import ( // if the command fails later. func (c *Cmder) Start(cmd *exec.Cmd) ( stdoutLines, stderrLines <-chan string, - waitError <-chan error, startErr error) { + waitError <-chan error, startErr error, +) { return start(cmd) } func start(cmd execCmd) (stdoutLines, stderrLines <-chan string, - waitError <-chan error, startErr error) { + waitError <-chan error, startErr error, +) { stop := make(chan struct{}) stdoutReady := make(chan struct{}) stdoutLinesCh := make(chan string) @@ -68,7 +70,8 @@ func start(cmd execCmd) (stdoutLines, stderrLines <-chan string, func streamToChannel(ready chan<- struct{}, stop <-chan struct{}, done chan<- struct{}, - stream io.Reader, lines chan<- string) { + stream io.Reader, lines chan<- string, +) { defer close(done) close(ready) scanner := bufio.NewScanner(stream) diff --git a/internal/configuration/settings/dnsblacklist.go b/internal/configuration/settings/dnsblacklist.go index 80e1853a..7853a8f2 100644 --- a/internal/configuration/settings/dnsblacklist.go +++ b/internal/configuration/settings/dnsblacklist.go @@ -76,7 +76,8 @@ func (b *DNSBlacklist) overrideWith(other DNSBlacklist) { } func (b DNSBlacklist) ToBlockBuilderSettings(client *http.Client) ( - settings blockbuilder.Settings) { + settings blockbuilder.Settings, +) { return blockbuilder.Settings{ Client: client, BlockMalicious: b.BlockMalicious, @@ -159,12 +160,11 @@ func (b *DNSBlacklist) read(r *reader.Reader) (err error) { return nil } -var ( - ErrPrivateAddressNotValid = errors.New("private address is not a valid IP or CIDR range") -) +var ErrPrivateAddressNotValid = errors.New("private address is not a valid IP or CIDR range") func readDoTPrivateAddresses(reader *reader.Reader) (ips []netip.Addr, - ipPrefixes []netip.Prefix, err error) { + ipPrefixes []netip.Prefix, err error, +) { privateAddresses := reader.CSV("DOT_PRIVATE_ADDRESS") if len(privateAddresses) == 0 { return nil, nil, nil diff --git a/internal/configuration/settings/dot.go b/internal/configuration/settings/dot.go index 3e0feb14..064ca22e 100644 --- a/internal/configuration/settings/dot.go +++ b/internal/configuration/settings/dot.go @@ -35,9 +35,7 @@ type DoT struct { Blacklist DNSBlacklist } -var ( - ErrDoTUpdatePeriodTooShort = errors.New("update period is too short") -) +var ErrDoTUpdatePeriodTooShort = errors.New("update period is too short") func (d DoT) validate() (err error) { const minUpdatePeriod = 30 * time.Second diff --git a/internal/configuration/settings/nordvpn_retro.go b/internal/configuration/settings/nordvpn_retro.go index 3cc517ed..d7e4c16a 100644 --- a/internal/configuration/settings/nordvpn_retro.go +++ b/internal/configuration/settings/nordvpn_retro.go @@ -4,7 +4,8 @@ package settings // and SERVER_REGIONS is now the continent field for servers. // TODO v4 remove. func nordvpnRetroRegion(selection ServerSelection, validRegions, validCountries []string) ( - updatedSelection ServerSelection) { + updatedSelection ServerSelection, +) { validRegionsMap := stringSliceToMap(validRegions) validCountriesMap := stringSliceToMap(validCountries) diff --git a/internal/configuration/settings/openvpn.go b/internal/configuration/settings/openvpn.go index ee13494e..853fa14d 100644 --- a/internal/configuration/settings/openvpn.go +++ b/internal/configuration/settings/openvpn.go @@ -155,7 +155,8 @@ func (o OpenVPN) validate(vpnProvider string) (err error) { } func validateOpenVPNConfigFilepath(isCustom bool, - confFile string) (err error) { + confFile string, +) (err error) { if !isCustom { return nil } @@ -179,7 +180,8 @@ func validateOpenVPNConfigFilepath(isCustom bool, } func validateOpenVPNClientCertificate(vpnProvider, - clientCert string) (err error) { + clientCert string, +) (err error) { switch vpnProvider { case providers.Airvpn, @@ -226,7 +228,8 @@ func validateOpenVPNClientKey(vpnProvider, clientKey string) (err error) { } func validateOpenVPNEncryptedKey(vpnProvider, - encryptedPrivateKey string) (err error) { + encryptedPrivateKey string, +) (err error) { if vpnProvider == providers.VPNSecure && encryptedPrivateKey == "" { return fmt.Errorf("%w", ErrMissingValue) } diff --git a/internal/configuration/settings/publicip.go b/internal/configuration/settings/publicip.go index 9cb642aa..3ab654c5 100644 --- a/internal/configuration/settings/publicip.go +++ b/internal/configuration/settings/publicip.go @@ -122,7 +122,8 @@ func (p *PublicIP) read(r *reader.Reader, warner Warner) (err error) { } func readPublicIPEnabled(r *reader.Reader, warner Warner) ( - enabled *bool, err error) { + enabled *bool, err error, +) { periodPtr, err := r.DurationPtr("PUBLICIP_PERIOD") // Retro-compatibility if err != nil { return nil, err diff --git a/internal/configuration/settings/serverselection.go b/internal/configuration/settings/serverselection.go index a257da15..fc3379e1 100644 --- a/internal/configuration/settings/serverselection.go +++ b/internal/configuration/settings/serverselection.go @@ -91,7 +91,8 @@ var ( ) func (ss *ServerSelection) validate(vpnServiceProvider string, - filterChoicesGetter FilterChoicesGetter, warner Warner) (err error) { + filterChoicesGetter FilterChoicesGetter, warner Warner, +) (err error) { switch ss.VPN { case vpn.OpenVPN, vpn.Wireguard: default: @@ -143,7 +144,8 @@ func (ss *ServerSelection) validate(vpnServiceProvider string, func getLocationFilterChoices(vpnServiceProvider string, ss *ServerSelection, filterChoicesGetter FilterChoicesGetter, warner Warner) ( - filterChoices models.FilterChoices, err error) { + filterChoices models.FilterChoices, err error, +) { filterChoices = filterChoicesGetter.GetFilterChoices(vpnServiceProvider) if vpnServiceProvider == providers.Surfshark { @@ -165,7 +167,8 @@ func getLocationFilterChoices(vpnServiceProvider string, // validateServerFilters validates filters against the choices given as arguments. // Set an argument to nil to pass the check for a particular filter. func validateServerFilters(settings ServerSelection, filterChoices models.FilterChoices, - vpnServiceProvider string, warner Warner) (err error) { + vpnServiceProvider string, warner Warner, +) (err error) { err = atLeastOneIsOneOfCaseInsensitive(settings.Countries, filterChoices.Countries, warner) if err != nil { return fmt.Errorf("%w: %w", ErrCountryNotValid, err) @@ -219,7 +222,8 @@ func validateServerFilters(settings ServerSelection, filterChoices models.Filter } func atLeastOneIsOneOfCaseInsensitive(values, choices []string, - warner Warner) (err error) { + warner Warner, +) (err error) { if len(values) > 0 && len(choices) == 0 { return fmt.Errorf("%w", validate.ErrNoChoice) } @@ -456,7 +460,8 @@ func (ss ServerSelection) WithDefaults(provider string) ServerSelection { } func (ss *ServerSelection) read(r *reader.Reader, - vpnProvider, vpnType string) (err error) { + vpnProvider, vpnType string, +) (err error) { ss.VPN = vpnType ss.TargetIP, err = r.NetipAddr("OPENVPN_ENDPOINT_IP", diff --git a/internal/configuration/settings/settings.go b/internal/configuration/settings/settings.go index b26632ff..eb34d7d1 100644 --- a/internal/configuration/settings/settings.go +++ b/internal/configuration/settings/settings.go @@ -38,7 +38,8 @@ type FilterChoicesGetter interface { // if one of them is not valid. // TODO v4 remove pointer for receiver (because of Surfshark). func (s *Settings) Validate(filterChoicesGetter FilterChoicesGetter, ipv6Supported bool, - warner Warner) (err error) { + warner Warner, +) (err error) { nameToValidation := map[string]func() error{ "control server": s.ControlServer.validate, "dns": s.DNS.validate, @@ -88,7 +89,8 @@ func (s *Settings) copy() (copied Settings) { } func (s *Settings) OverrideWith(other Settings, - filterChoicesGetter FilterChoicesGetter, ipv6Supported bool, warner Warner) (err error) { + filterChoicesGetter FilterChoicesGetter, ipv6Supported bool, warner Warner, +) (err error) { patchedSettings := s.copy() patchedSettings.ControlServer.overrideWith(other.ControlServer) patchedSettings.DNS.overrideWith(other.DNS) diff --git a/internal/configuration/settings/surfshark_retro.go b/internal/configuration/settings/surfshark_retro.go index cb812c03..96ff3119 100644 --- a/internal/configuration/settings/surfshark_retro.go +++ b/internal/configuration/settings/surfshark_retro.go @@ -7,7 +7,8 @@ import ( ) func surfsharkRetroRegion(selection ServerSelection) ( - updatedSelection ServerSelection) { + updatedSelection ServerSelection, +) { locationData := servers.LocationData() retroToLocation := make(map[string]servers.ServerLocation, len(locationData)) diff --git a/internal/configuration/sources/files/wireguard.go b/internal/configuration/sources/files/wireguard.go index ebea1026..0b86f662 100644 --- a/internal/configuration/sources/files/wireguard.go +++ b/internal/configuration/sources/files/wireguard.go @@ -34,9 +34,7 @@ type WireguardConfig struct { EndpointPort *string } -var ( - regexINISectionNotExist = regexp.MustCompile(`^section ".+" does not exist$`) -) +var regexINISectionNotExist = regexp.MustCompile(`^section ".+" does not exist$`) func ParseWireguardConf(path string) (config WireguardConfig, err error) { iniFile, err := ini.InsensitiveLoad(path) @@ -68,18 +66,18 @@ func ParseWireguardConf(path string) (config WireguardConfig, err error) { } func parseWireguardInterfaceSection(interfaceSection *ini.Section) ( - privateKey, addresses *string) { + privateKey, addresses *string, +) { privateKey = getINIKeyFromSection(interfaceSection, "PrivateKey") addresses = getINIKeyFromSection(interfaceSection, "Address") return privateKey, addresses } -var ( - ErrEndpointHostNotIP = errors.New("endpoint host is not an IP") -) +var ErrEndpointHostNotIP = errors.New("endpoint host is not an IP") func parseWireguardPeerSection(peerSection *ini.Section) ( - preSharedKey, publicKey, endpointIP, endpointPort *string) { + preSharedKey, publicKey, endpointIP, endpointPort *string, +) { preSharedKey = getINIKeyFromSection(peerSection, "PresharedKey") publicKey = getINIKeyFromSection(peerSection, "PublicKey") endpoint := getINIKeyFromSection(peerSection, "Endpoint") @@ -96,9 +94,7 @@ func parseWireguardPeerSection(peerSection *ini.Section) ( return preSharedKey, publicKey, endpointIP, endpointPort } -var ( - regexINIKeyNotExist = regexp.MustCompile(`key ".*" not exists$`) -) +var regexINIKeyNotExist = regexp.MustCompile(`key ".*" not exists$`) func getINIKeyFromSection(section *ini.Section, key string) (value *string) { iniKey, err := section.GetKey(key) diff --git a/internal/configuration/sources/files/wireguard_test.go b/internal/configuration/sources/files/wireguard_test.go index 26ac77e9..53d9c838 100644 --- a/internal/configuration/sources/files/wireguard_test.go +++ b/internal/configuration/sources/files/wireguard_test.go @@ -77,7 +77,7 @@ PresharedKey = YJ680VN+dGrdsWNjSFqZ6vvwuiNhbq502ZL3G7Q3o3g= t.Parallel() configFile := filepath.Join(t.TempDir(), "wg.conf") - const permission = fs.FileMode(0600) + const permission = fs.FileMode(0o600) err := os.WriteFile(configFile, []byte(testCase.fileContent), permission) require.NoError(t, err) diff --git a/internal/configuration/sources/secrets/reader_test.go b/internal/configuration/sources/secrets/reader_test.go index 35577eba..0ba8d449 100644 --- a/internal/configuration/sources/secrets/reader_test.go +++ b/internal/configuration/sources/secrets/reader_test.go @@ -39,7 +39,7 @@ func Test_Source_Get(t *testing.T) { "empty_secret_file": { makeSource: func(tempDir string) (source *Source, err error) { secretFilepath := filepath.Join(tempDir, "test_file") - const permission = fs.FileMode(0600) + const permission = fs.FileMode(0o600) err = os.WriteFile(secretFilepath, nil, permission) if err != nil { return nil, err @@ -55,7 +55,7 @@ func Test_Source_Get(t *testing.T) { "default_secret_file": { makeSource: func(tempDir string) (source *Source, err error) { secretFilepath := filepath.Join(tempDir, "test_file") - const permission = fs.FileMode(0600) + const permission = fs.FileMode(0o600) err = os.WriteFile(secretFilepath, []byte{'A'}, permission) if err != nil { return nil, err @@ -72,7 +72,7 @@ func Test_Source_Get(t *testing.T) { "env_specified_secret_file": { makeSource: func(tempDir string) (source *Source, err error) { secretFilepath := filepath.Join(tempDir, "test_file_custom") - const permission = fs.FileMode(0600) + const permission = fs.FileMode(0o600) err = os.WriteFile(secretFilepath, []byte{'A'}, permission) if err != nil { return nil, err diff --git a/internal/dns/loop.go b/internal/dns/loop.go index f37766e2..95739cda 100644 --- a/internal/dns/loop.go +++ b/internal/dns/loop.go @@ -37,7 +37,8 @@ type Loop struct { const defaultBackoffTime = 10 * time.Second func NewLoop(settings settings.DNS, - client *http.Client, logger Logger) (loop *Loop, err error) { + client *http.Client, logger Logger, +) (loop *Loop, err error) { start := make(chan struct{}) running := make(chan models.LoopStatus) stop := make(chan struct{}) diff --git a/internal/dns/settings.go b/internal/dns/settings.go index 4b11ef03..4e07bb85 100644 --- a/internal/dns/settings.go +++ b/internal/dns/settings.go @@ -16,13 +16,15 @@ import ( func (l *Loop) GetSettings() (settings settings.DNS) { return l.state.GetSettings() } func (l *Loop) SetSettings(ctx context.Context, settings settings.DNS) ( - outcome string) { + outcome string, +) { return l.state.SetSettings(ctx, settings) } func buildDoTSettings(settings settings.DNS, filter *mapfilter.Filter, logger Logger) ( - dotSettings dot.ServerSettings, err error) { + dotSettings dot.ServerSettings, err error, +) { var middlewares []dot.Middleware if *settings.DoT.Caching { diff --git a/internal/dns/state/settings.go b/internal/dns/state/settings.go index 432a42aa..4384e905 100644 --- a/internal/dns/state/settings.go +++ b/internal/dns/state/settings.go @@ -15,7 +15,8 @@ func (s *State) GetSettings() (settings settings.DNS) { } func (s *State) SetSettings(ctx context.Context, settings settings.DNS) ( - outcome string) { + outcome string, +) { s.settingsMu.Lock() settingsUnchanged := reflect.DeepEqual(s.settings, settings) diff --git a/internal/dns/state/state.go b/internal/dns/state/state.go index b3419559..b8e6bf52 100644 --- a/internal/dns/state/state.go +++ b/internal/dns/state/state.go @@ -10,7 +10,8 @@ import ( func New(statusApplier StatusApplier, settings settings.DNS, - updateTicker chan<- struct{}) *State { + updateTicker chan<- struct{}, +) *State { return &State{ statusApplier: statusApplier, settings: settings, diff --git a/internal/dns/status.go b/internal/dns/status.go index d7f7d2c2..a3935f1e 100644 --- a/internal/dns/status.go +++ b/internal/dns/status.go @@ -11,6 +11,7 @@ func (l *Loop) GetStatus() (status models.LoopStatus) { } func (l *Loop) ApplyStatus(ctx context.Context, status models.LoopStatus) ( - outcome string, err error) { + outcome string, err error, +) { return l.statusManager.ApplyStatus(ctx, status) } diff --git a/internal/firewall/delete.go b/internal/firewall/delete.go index 7ad2a3b1..ed6a1132 100644 --- a/internal/firewall/delete.go +++ b/internal/firewall/delete.go @@ -33,7 +33,8 @@ func isDeleteMatchInstruction(instruction string) bool { } func deleteIPTablesRule(ctx context.Context, iptablesBinary, instruction string, - runner CmdRunner, logger Logger) (err error) { + runner CmdRunner, logger Logger, +) (err error) { targetRule, err := parseIptablesInstruction(instruction) if err != nil { return fmt.Errorf("parsing iptables command: %w", err) @@ -69,9 +70,12 @@ func deleteIPTablesRule(ctx context.Context, iptablesBinary, instruction string, // It returns 0 if the rule is not found. func findLineNumber(ctx context.Context, iptablesBinary string, instruction iptablesInstruction, runner CmdRunner, logger Logger) ( - lineNumber uint16, err error) { - listFlags := []string{"-t", instruction.table, "-L", instruction.chain, - "--line-numbers", "-n", "-v"} + lineNumber uint16, err error, +) { + listFlags := []string{ + "-t", instruction.table, "-L", instruction.chain, + "--line-numbers", "-n", "-v", + } cmd := exec.CommandContext(ctx, iptablesBinary, listFlags...) // #nosec G204 logger.Debug(cmd.String()) output, err := runner.Run(cmd) diff --git a/internal/firewall/firewall.go b/internal/firewall/firewall.go index b488ca2b..8114d550 100644 --- a/internal/firewall/firewall.go +++ b/internal/firewall/firewall.go @@ -36,7 +36,8 @@ type Config struct { //nolint:maligned // if no iptables implementation is available. func NewConfig(ctx context.Context, logger Logger, runner CmdRunner, defaultRoutes []routing.DefaultRoute, - localNetworks []routing.LocalNetwork) (config *Config, err error) { + localNetworks []routing.LocalNetwork, +) (config *Config, err error) { iptables, err := checkIptablesSupport(ctx, runner, "iptables", "iptables-nft", "iptables-legacy") if err != nil { return nil, err diff --git a/internal/firewall/ip6tables.go b/internal/firewall/ip6tables.go index 54bd3eae..397ab047 100644 --- a/internal/firewall/ip6tables.go +++ b/internal/firewall/ip6tables.go @@ -12,7 +12,8 @@ import ( // and returns the iptables path that is supported. If none work, an // empty string path is returned. func findIP6tablesSupported(ctx context.Context, runner CmdRunner) ( - ip6tablesPath string, err error) { + ip6tablesPath string, err error, +) { ip6tablesPath, err = checkIptablesSupport(ctx, runner, "ip6tables", "ip6tables-nft", "ip6tables-legacy") if errors.Is(err, ErrIPTablesNotSupported) { return "", nil diff --git a/internal/firewall/iptables.go b/internal/firewall/iptables.go index 8a51736a..0b1002f5 100644 --- a/internal/firewall/iptables.go +++ b/internal/firewall/iptables.go @@ -112,7 +112,8 @@ func (c *Config) acceptInputThroughInterface(ctx context.Context, intf string, r } func (c *Config) acceptInputToSubnet(ctx context.Context, intf string, - destination netip.Prefix, remove bool) error { + destination netip.Prefix, remove bool, +) error { interfaceFlag := "-i " + intf if intf == "*" { // all interfaces interfaceFlag = "" @@ -144,7 +145,8 @@ func (c *Config) acceptEstablishedRelatedTraffic(ctx context.Context, remove boo } func (c *Config) acceptOutputTrafficToVPN(ctx context.Context, - defaultInterface string, connection models.Connection, remove bool) error { + defaultInterface string, connection models.Connection, remove bool, +) error { protocol := connection.Protocol if protocol == "tcp-client" { protocol = "tcp" //nolint:goconst @@ -162,7 +164,8 @@ func (c *Config) acceptOutputTrafficToVPN(ctx context.Context, // Thanks to @npawelek. func (c *Config) acceptOutputFromIPToSubnet(ctx context.Context, - intf string, sourceIP netip.Addr, destinationSubnet netip.Prefix, remove bool) error { + intf string, sourceIP netip.Addr, destinationSubnet netip.Prefix, remove bool, +) error { doIPv4 := sourceIP.Is4() && destinationSubnet.Addr().Is4() interfaceFlag := "-o " + intf @@ -183,7 +186,8 @@ func (c *Config) acceptOutputFromIPToSubnet(ctx context.Context, // NDP uses multicast address (theres no broadcast in IPv6 like ARP uses in IPv4). func (c *Config) acceptIpv6MulticastOutput(ctx context.Context, - intf string, remove bool) error { + intf string, remove bool, +) error { interfaceFlag := "-o " + intf if intf == "*" { // all interfaces interfaceFlag = "" @@ -207,7 +211,8 @@ func (c *Config) acceptInputToPort(ctx context.Context, intf string, port uint16 // Used for VPN server side port forwarding, with intf set to the VPN tunnel interface. func (c *Config) redirectPort(ctx context.Context, intf string, - sourcePort, destinationPort uint16, remove bool) (err error) { + sourcePort, destinationPort uint16, remove bool, +) (err error) { interfaceFlag := "-i " + intf if intf == "*" { // all interfaces interfaceFlag = "" diff --git a/internal/firewall/list.go b/internal/firewall/list.go index c47f0d84..14b612d7 100644 --- a/internal/firewall/list.go +++ b/internal/firewall/list.go @@ -32,9 +32,7 @@ type chainRule struct { ctstate []string // for example ["RELATED","ESTABLISHED"]. Can be empty. } -var ( - ErrChainListMalformed = errors.New("iptables chain list output is malformed") -) +var ErrChainListMalformed = errors.New("iptables chain list output is malformed") func parseChain(iptablesOutput string) (c chain, err error) { // Text example: @@ -146,9 +144,7 @@ func parseChainGeneralDataLine(line string) (base chain, err error) { return base, nil } -var ( - ErrChainRuleMalformed = errors.New("chain rule is malformed") -) +var ErrChainRuleMalformed = errors.New("chain rule is malformed") func parseChainRuleLine(line string) (rule chainRule, err error) { line = strings.TrimSpace(line) @@ -300,9 +296,7 @@ func parsePortsCSV(s string) (ports []uint16, err error) { return ports, nil } -var ( - ErrLineNumberIsZero = errors.New("line number is zero") -) +var ErrLineNumberIsZero = errors.New("line number is zero") func parseLineNumber(s string) (n uint16, err error) { const base, bitLength = 10, 16 @@ -315,9 +309,7 @@ func parseLineNumber(s string) (n uint16, err error) { return uint16(lineNumber), nil } -var ( - ErrTargetUnknown = errors.New("unknown target") -) +var ErrTargetUnknown = errors.New("unknown target") func checkTarget(target string) (err error) { switch target { @@ -327,9 +319,7 @@ func checkTarget(target string) (err error) { return fmt.Errorf("%w: %s", ErrTargetUnknown, target) } -var ( - ErrProtocolUnknown = errors.New("unknown protocol") -) +var ErrProtocolUnknown = errors.New("unknown protocol") func parseProtocol(s string) (protocol string, err error) { switch s { @@ -344,9 +334,7 @@ func parseProtocol(s string) (protocol string, err error) { return protocol, nil } -var ( - ErrMetricSizeMalformed = errors.New("metric size is malformed") -) +var ErrMetricSizeMalformed = errors.New("metric size is malformed") // parseMetricSize parses a metric size string like 140K or 226M and // returns the raw integer matching it. diff --git a/internal/firewall/parse.go b/internal/firewall/parse.go index bb8dd9e0..d2d046cb 100644 --- a/internal/firewall/parse.go +++ b/internal/firewall/parse.go @@ -70,9 +70,7 @@ func ipPrefixesEqual(instruction, chainRule netip.Prefix) bool { (!instruction.IsValid() && chainRule.Bits() == 0 && chainRule.Addr().IsUnspecified()) } -var ( - ErrIptablesCommandMalformed = errors.New("iptables command is malformed") -) +var ErrIptablesCommandMalformed = errors.New("iptables command is malformed") func parseIptablesInstruction(s string) (instruction iptablesInstruction, err error) { if s == "" { diff --git a/internal/firewall/redirect.go b/internal/firewall/redirect.go index 44f20788..96e41804 100644 --- a/internal/firewall/redirect.go +++ b/internal/firewall/redirect.go @@ -11,7 +11,8 @@ import ( // If the destination port is zero, the redirection for the source port is removed // and no new redirection is added. func (c *Config) RedirectPort(ctx context.Context, intf string, sourcePort, - destinationPort uint16) (err error) { + destinationPort uint16, +) (err error) { c.stateMutex.Lock() defer c.stateMutex.Unlock() @@ -90,7 +91,8 @@ func (p *portRedirections) remove(intf string, sourcePort uint16) { } func (p *portRedirections) check(dryRun portRedirection) (alreadyExists bool, - conflict *portRedirection) { + conflict *portRedirection, +) { slice := *p for _, redirection := range slice { interfaceMatch := redirection.interfaceName == "" || diff --git a/internal/firewall/support.go b/internal/firewall/support.go index f637baf5..d7164255 100644 --- a/internal/firewall/support.go +++ b/internal/firewall/support.go @@ -18,7 +18,8 @@ var ( ) func checkIptablesSupport(ctx context.Context, runner CmdRunner, - iptablesPathsToTry ...string) (iptablesPath string, err error) { + iptablesPathsToTry ...string, +) (iptablesPath string, err error) { iptablesPathToUnsupportedMessage := make(map[string]string, len(iptablesPathsToTry)) for _, pathToTest := range iptablesPathsToTry { ok, unsupportedMessage, err := testIptablesPath(ctx, pathToTest, runner) @@ -61,7 +62,8 @@ func checkIptablesSupport(ctx context.Context, runner CmdRunner, func testIptablesPath(ctx context.Context, path string, runner CmdRunner) (ok bool, unsupportedMessage string, - criticalErr error) { + criticalErr error, +) { // Just listing iptables rules often work but we need // to modify them to ensure we can support the iptables // being tested. diff --git a/internal/firewall/support_test.go b/internal/firewall/support_test.go index 2a90a2f0..ab0edbad 100644 --- a/internal/firewall/support_test.go +++ b/internal/firewall/support_test.go @@ -116,8 +116,7 @@ func Test_checkIptablesSupport(t *testing.T) { runner := testCase.buildRunner(ctrl) - iptablesPath, err := - checkIptablesSupport(ctx, runner, testCase.iptablesPathsToTry...) + iptablesPath, err := checkIptablesSupport(ctx, runner, testCase.iptablesPathsToTry...) require.ErrorIs(t, err, testCase.errSentinel) if testCase.errSentinel != nil { @@ -254,8 +253,7 @@ func Test_testIptablesPath(t *testing.T) { runner := testCase.buildRunner(ctrl) - ok, unsupportedMessage, criticalErr := - testIptablesPath(ctx, path, runner) + ok, unsupportedMessage, criticalErr := testIptablesPath(ctx, path, runner) assert.Equal(t, testCase.ok, ok) assert.Equal(t, testCase.unsupportedMessage, unsupportedMessage) diff --git a/internal/firewall/vpn.go b/internal/firewall/vpn.go index a585ce1d..4e906854 100644 --- a/internal/firewall/vpn.go +++ b/internal/firewall/vpn.go @@ -8,7 +8,8 @@ import ( ) func (c *Config) SetVPNConnection(ctx context.Context, - connection models.Connection, vpnIntf string) (err error) { + connection models.Connection, vpnIntf string, +) (err error) { c.stateMutex.Lock() defer c.stateMutex.Unlock() diff --git a/internal/healthcheck/client.go b/internal/healthcheck/client.go index f8991483..7675a4f3 100644 --- a/internal/healthcheck/client.go +++ b/internal/healthcheck/client.go @@ -8,9 +8,7 @@ import ( "net/http" ) -var ( - ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK") -) +var ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK") type Client struct { httpClient *http.Client diff --git a/internal/healthcheck/server.go b/internal/healthcheck/server.go index 11b534b0..c3a3a6be 100644 --- a/internal/healthcheck/server.go +++ b/internal/healthcheck/server.go @@ -17,7 +17,8 @@ type Server struct { } func NewServer(config settings.Health, - logger Logger, vpnLoop StatusApplier) *Server { + logger Logger, vpnLoop StatusApplier, +) *Server { return &Server{ logger: logger, handler: newHandler(), diff --git a/internal/httpproxy/handler.go b/internal/httpproxy/handler.go index 4921a8cd..25da0769 100644 --- a/internal/httpproxy/handler.go +++ b/internal/httpproxy/handler.go @@ -8,14 +8,16 @@ import ( ) func newHandler(ctx context.Context, wg *sync.WaitGroup, logger Logger, - stealth, verbose bool, username, password string) http.Handler { + stealth, verbose bool, username, password string, +) http.Handler { const httpTimeout = 24 * time.Hour return &handler{ ctx: ctx, wg: wg, client: &http.Client{ Timeout: httpTimeout, - CheckRedirect: returnRedirect}, + CheckRedirect: returnRedirect, + }, logger: logger, verbose: verbose, stealth: stealth, diff --git a/internal/httpproxy/server.go b/internal/httpproxy/server.go index 0912b3bd..9c301eec 100644 --- a/internal/httpproxy/server.go +++ b/internal/httpproxy/server.go @@ -18,7 +18,8 @@ type Server struct { func New(ctx context.Context, address string, logger Logger, stealth, verbose bool, username, password string, - readHeaderTimeout, readTimeout time.Duration) *Server { + readHeaderTimeout, readTimeout time.Duration, +) *Server { wg := &sync.WaitGroup{} return &Server{ address: address, diff --git a/internal/httpproxy/settings.go b/internal/httpproxy/settings.go index 48cef59c..ffab3155 100644 --- a/internal/httpproxy/settings.go +++ b/internal/httpproxy/settings.go @@ -11,6 +11,7 @@ func (l *Loop) GetSettings() (settings settings.HTTPProxy) { } func (l *Loop) SetSettings(ctx context.Context, settings settings.HTTPProxy) ( - outcome string) { + outcome string, +) { return l.state.SetSettings(ctx, settings) } diff --git a/internal/httpproxy/state/settings.go b/internal/httpproxy/state/settings.go index 7829ffe1..a30a8f86 100644 --- a/internal/httpproxy/state/settings.go +++ b/internal/httpproxy/state/settings.go @@ -15,7 +15,8 @@ func (s *State) GetSettings() (settings settings.HTTPProxy) { } func (s *State) SetSettings(ctx context.Context, - settings settings.HTTPProxy) (outcome string) { + settings settings.HTTPProxy, +) (outcome string) { s.settingsMu.Lock() settingsUnchanged := reflect.DeepEqual(settings, s.settings) if settingsUnchanged { diff --git a/internal/httpproxy/state/state.go b/internal/httpproxy/state/state.go index e611ad85..e35aa7fe 100644 --- a/internal/httpproxy/state/state.go +++ b/internal/httpproxy/state/state.go @@ -9,7 +9,8 @@ import ( ) func New(statusApplier StatusApplier, - settings settings.HTTPProxy) *State { + settings settings.HTTPProxy, +) *State { return &State{ statusApplier: statusApplier, settings: settings, diff --git a/internal/httpproxy/status.go b/internal/httpproxy/status.go index 461dc5b7..3a5bddc5 100644 --- a/internal/httpproxy/status.go +++ b/internal/httpproxy/status.go @@ -11,6 +11,7 @@ func (l *Loop) GetStatus() (status models.LoopStatus) { } func (l *Loop) ApplyStatus(ctx context.Context, status models.LoopStatus) ( - outcome string, err error) { + outcome string, err error, +) { return l.statusManager.ApplyStatus(ctx, status) } diff --git a/internal/loopstate/apply.go b/internal/loopstate/apply.go index 8903364c..4f9cc23d 100644 --- a/internal/loopstate/apply.go +++ b/internal/loopstate/apply.go @@ -16,7 +16,8 @@ var ErrInvalidStatus = errors.New("invalid status") // matches the requested one. It is thread safe and a synchronous call // since it waits to the loop to fully change its status. func (s *State) ApplyStatus(ctx context.Context, status models.LoopStatus) ( - outcome string, err error) { + outcome string, err error, +) { // prevent simultaneous loop changes by restricting // multiple ApplyStatus calls to run sequentially. s.loopMu.Lock() diff --git a/internal/loopstate/state.go b/internal/loopstate/state.go index bbbe9335..118229f0 100644 --- a/internal/loopstate/state.go +++ b/internal/loopstate/state.go @@ -8,7 +8,8 @@ import ( func New(status models.LoopStatus, start chan<- struct{}, running <-chan models.LoopStatus, - stop chan<- struct{}, stopped <-chan struct{}) *State { + stop chan<- struct{}, stopped <-chan struct{}, +) *State { return &State{ status: status, start: start, diff --git a/internal/mod/info.go b/internal/mod/info.go index bcbf3d24..9eed2f45 100644 --- a/internal/mod/info.go +++ b/internal/mod/info.go @@ -26,9 +26,7 @@ type moduleInfo struct { dependencyPaths []string } -var ( - ErrModulesDirectoryNotFound = errors.New("modules directory not found") -) +var ErrModulesDirectoryNotFound = errors.New("modules directory not found") func getModulesInfo() (modulesInfo map[string]moduleInfo, err error) { var utsName unix.Utsname @@ -177,9 +175,7 @@ func getLoadedModules(modulesInfo map[string]moduleInfo) (err error) { return nil } -var ( - ErrModulePathNotFound = errors.New("module path not found") -) +var ErrModulePathNotFound = errors.New("module path not found") func findModulePath(moduleName string, modulesInfo map[string]moduleInfo) (modulePath string, err error) { // Kernel module names can have underscores or hyphens in their names, diff --git a/internal/models/markdown.go b/internal/models/markdown.go index b725d974..4c45346e 100644 --- a/internal/models/markdown.go +++ b/internal/models/markdown.go @@ -109,15 +109,15 @@ func (s *Servers) toMarkdown(vpnProvider string) (formatted string, err error) { return formatted, nil } -var ( - ErrMarkdownHeadersNotDefined = errors.New("markdown headers not defined") -) +var ErrMarkdownHeadersNotDefined = errors.New("markdown headers not defined") func getMarkdownHeaders(vpnProvider string) (headers []string, err error) { switch vpnProvider { case providers.Airvpn: - return []string{regionHeader, countryHeader, cityHeader, vpnHeader, - udpHeader, tcpHeader, hostnameHeader, nameHeader}, nil + return []string{ + regionHeader, countryHeader, cityHeader, vpnHeader, + udpHeader, tcpHeader, hostnameHeader, nameHeader, + }, nil case providers.Cyberghost: return []string{countryHeader, hostnameHeader, tcpHeader, udpHeader}, nil case providers.Expressvpn: @@ -145,15 +145,19 @@ func getMarkdownHeaders(vpnProvider string) (headers []string, err error) { case providers.Privatevpn: return []string{countryHeader, cityHeader, hostnameHeader}, nil case providers.Protonvpn: - return []string{countryHeader, regionHeader, cityHeader, hostnameHeader, vpnHeader, - freeHeader, portForwardHeader, secureHeader, torHeader}, nil + return []string{ + countryHeader, regionHeader, cityHeader, hostnameHeader, vpnHeader, + freeHeader, portForwardHeader, secureHeader, torHeader, + }, nil case providers.Purevpn: return []string{countryHeader, regionHeader, cityHeader, hostnameHeader, tcpHeader, udpHeader}, nil case providers.SlickVPN: return []string{regionHeader, countryHeader, cityHeader, hostnameHeader}, nil case providers.Surfshark: - return []string{regionHeader, countryHeader, cityHeader, hostnameHeader, - vpnHeader, multiHopHeader, tcpHeader, udpHeader}, nil + return []string{ + regionHeader, countryHeader, cityHeader, hostnameHeader, + vpnHeader, multiHopHeader, tcpHeader, udpHeader, + }, nil case providers.Torguard: return []string{countryHeader, cityHeader, hostnameHeader, tcpHeader, udpHeader}, nil case providers.VPNSecure: diff --git a/internal/models/servers.go b/internal/models/servers.go index 7f719086..4aba19a9 100644 --- a/internal/models/servers.go +++ b/internal/models/servers.go @@ -158,9 +158,7 @@ type Servers struct { Servers []Server `json:"servers,omitempty"` } -var ( - ErrServersFormatNotSupported = errors.New("servers format not supported") -) +var ErrServersFormatNotSupported = errors.New("servers format not supported") func (s *Servers) Format(vpnProvider, format string) (formatted string, err error) { switch format { diff --git a/internal/natpmp/checks.go b/internal/natpmp/checks.go index fddb0656..f5cc4edb 100644 --- a/internal/natpmp/checks.go +++ b/internal/natpmp/checks.go @@ -6,9 +6,7 @@ import ( "fmt" ) -var ( - ErrRequestSizeTooSmall = errors.New("message size is too small") -) +var ErrRequestSizeTooSmall = errors.New("message size is too small") func checkRequest(request []byte) (err error) { const minMessageSize = 2 // version number + operation code @@ -28,7 +26,8 @@ var ( ) func checkResponse(response []byte, expectedOperationCode byte, - expectedResponseSize uint) (err error) { + expectedResponseSize uint, +) (err error) { const minResponseSize = 4 if len(response) < minResponseSize { return fmt.Errorf("%w: need at least %d bytes and got %d byte(s)", diff --git a/internal/natpmp/externaladdress.go b/internal/natpmp/externaladdress.go index 971a59e1..304df85f 100644 --- a/internal/natpmp/externaladdress.go +++ b/internal/natpmp/externaladdress.go @@ -13,7 +13,8 @@ import ( // See https://www.ietf.org/rfc/rfc6886.html#section-3.2 func (c *Client) ExternalAddress(ctx context.Context, gateway netip.Addr) ( durationSinceStartOfEpoch time.Duration, - externalIPv4Address netip.Addr, err error) { + externalIPv4Address netip.Addr, err error, +) { request := []byte{0, 0} // version 0, operationCode 0 const responseSize = 12 response, err := c.rpc(ctx, gateway, request, responseSize) diff --git a/internal/natpmp/externaladdress_test.go b/internal/natpmp/externaladdress_test.go index d040aea7..a479dad4 100644 --- a/internal/natpmp/externaladdress_test.go +++ b/internal/natpmp/externaladdress_test.go @@ -57,8 +57,7 @@ func Test_Client_ExternalAddress(t *testing.T) { maxRetries: 1, } - durationSinceStartOfEpoch, externalIPv4Address, err := - client.ExternalAddress(testCase.ctx, testCase.gateway) + durationSinceStartOfEpoch, externalIPv4Address, err := client.ExternalAddress(testCase.ctx, testCase.gateway) assert.ErrorIs(t, err, testCase.err) if testCase.err != nil { assert.EqualError(t, err, testCase.errMessage) diff --git a/internal/natpmp/helpers_test.go b/internal/natpmp/helpers_test.go index 8cd735b5..4e64c58a 100644 --- a/internal/natpmp/helpers_test.go +++ b/internal/natpmp/helpers_test.go @@ -27,7 +27,8 @@ type udpExchange struct { // port is dynamically assigned by the OS so calling tests // can run in parallel. func launchUDPServer(t *testing.T, exchanges []udpExchange) ( - remoteAddress *net.UDPAddr) { + remoteAddress *net.UDPAddr, +) { t.Helper() conn, err := net.ListenUDP("udp", nil) diff --git a/internal/natpmp/portmapping.go b/internal/natpmp/portmapping.go index 098adf3b..52d0ee1b 100644 --- a/internal/natpmp/portmapping.go +++ b/internal/natpmp/portmapping.go @@ -21,7 +21,8 @@ func (c *Client) AddPortMapping(ctx context.Context, gateway netip.Addr, protocol string, internalPort, requestedExternalPort uint16, lifetime time.Duration) (durationSinceStartOfEpoch time.Duration, assignedInternalPort, assignedExternalPort uint16, assignedLifetime time.Duration, - err error) { + err error, +) { lifetimeSecondsFloat := lifetime.Seconds() const maxLifetimeSeconds = uint64(^uint32(0)) if uint64(lifetimeSecondsFloat) > maxLifetimeSeconds { diff --git a/internal/natpmp/portmapping_test.go b/internal/natpmp/portmapping_test.go index 98d90143..b89e3d84 100644 --- a/internal/natpmp/portmapping_test.go +++ b/internal/natpmp/portmapping_test.go @@ -127,10 +127,9 @@ func Test_Client_AddPortMapping(t *testing.T) { } durationSinceStartOfEpoch, assignedInternalPort, - assignedExternalPort, assignedLifetime, err := - client.AddPortMapping(testCase.ctx, testCase.gateway, - testCase.protocol, testCase.internalPort, - testCase.requestedExternalPort, testCase.lifetime) + assignedExternalPort, assignedLifetime, err := client.AddPortMapping(testCase.ctx, testCase.gateway, + testCase.protocol, testCase.internalPort, + testCase.requestedExternalPort, testCase.lifetime) assert.Equal(t, testCase.durationSinceStartOfEpoch, durationSinceStartOfEpoch) assert.Equal(t, testCase.assignedInternalPort, assignedInternalPort) diff --git a/internal/natpmp/rpc.go b/internal/natpmp/rpc.go index 75cb0ed7..9fb990f2 100644 --- a/internal/natpmp/rpc.go +++ b/internal/natpmp/rpc.go @@ -18,7 +18,8 @@ var ( func (c *Client) rpc(ctx context.Context, gateway netip.Addr, request []byte, responseSize uint) ( - response []byte, err error) { + response []byte, err error, +) { if gateway.IsUnspecified() || !gateway.IsValid() { return nil, fmt.Errorf("%w", ErrGatewayIPUnspecified) } diff --git a/internal/netlink/address.go b/internal/netlink/address.go index 5d036e6e..eeadc2a4 100644 --- a/internal/netlink/address.go +++ b/internal/netlink/address.go @@ -7,7 +7,8 @@ import ( ) func (n *NetLink) AddrList(link Link, family int) ( - addresses []Addr, err error) { + addresses []Addr, err error, +) { netlinkLink := linkToNetlinkLink(&link) netlinkAddresses, err := netlink.AddrList(netlinkLink, family) if err != nil { diff --git a/internal/netlink/address_unspecified.go b/internal/netlink/address_unspecified.go index f4df3c35..1583bc99 100644 --- a/internal/netlink/address_unspecified.go +++ b/internal/netlink/address_unspecified.go @@ -3,7 +3,8 @@ package netlink func (n *NetLink) AddrList(link Link, family int) ( - addresses []Addr, err error) { + addresses []Addr, err error, +) { panic("not implemented") } diff --git a/internal/netlink/route_unspecified.go b/internal/netlink/route_unspecified.go index 14816b01..e93fc93c 100644 --- a/internal/netlink/route_unspecified.go +++ b/internal/netlink/route_unspecified.go @@ -3,7 +3,8 @@ package netlink func (n *NetLink) RouteList(family int) ( - routes []Route, err error) { + routes []Route, err error, +) { panic("not implemented") } diff --git a/internal/openvpn/auth.go b/internal/openvpn/auth.go index 8279d5b9..63d3265b 100644 --- a/internal/openvpn/auth.go +++ b/internal/openvpn/auth.go @@ -23,7 +23,7 @@ func writeIfDifferent(path, content string, puid, pgid int) (err error) { return fmt.Errorf("obtaining file information: %w", err) } - const perm = os.FileMode(0400) + const perm = os.FileMode(0o400) var writeData, setChown bool if os.IsNotExist(err) { writeData = true diff --git a/internal/openvpn/config.go b/internal/openvpn/config.go index 33ecbf33..6f8edaec 100644 --- a/internal/openvpn/config.go +++ b/internal/openvpn/config.go @@ -6,7 +6,7 @@ import ( ) func (c *Configurator) WriteConfig(lines []string) error { - const permission = 0644 + const permission = 0o644 file, err := os.OpenFile(c.configPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, permission) if err != nil { return err diff --git a/internal/openvpn/extract/data.go b/internal/openvpn/extract/data.go index 25dbd8d5..bc658889 100644 --- a/internal/openvpn/extract/data.go +++ b/internal/openvpn/extract/data.go @@ -14,7 +14,8 @@ var ( // Data extracts the lines and connection from the OpenVPN configuration file. func (e *Extractor) Data(filepath string) (lines []string, - connection models.Connection, err error) { + connection models.Connection, err error, +) { lines, err = readCustomConfigLines(filepath) if err != nil { return nil, connection, fmt.Errorf("reading configuration file: %w", err) diff --git a/internal/openvpn/extract/extract.go b/internal/openvpn/extract/extract.go index 590985ee..64ad6181 100644 --- a/internal/openvpn/extract/extract.go +++ b/internal/openvpn/extract/extract.go @@ -11,12 +11,11 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -var ( - errRemoteLineNotFound = errors.New("remote line not found") -) +var errRemoteLineNotFound = errors.New("remote line not found") func extractDataFromLines(lines []string) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { for i, line := range lines { hashSymbolIndex := strings.Index(line, "#") if hashSymbolIndex >= 0 { @@ -54,7 +53,8 @@ func extractDataFromLines(lines []string) ( } func extractDataFromLine(line string) ( - ip netip.Addr, port uint16, protocol string, err error) { + ip netip.Addr, port uint16, protocol string, err error, +) { switch { case strings.HasPrefix(line, "proto "): protocol, err = extractProto(line) @@ -108,7 +108,8 @@ var ( ) func extractRemote(line string) (ip netip.Addr, port uint16, - protocol string, err error) { + protocol string, err error, +) { fields := strings.Fields(line) n := len(fields) @@ -146,9 +147,7 @@ func extractRemote(line string) (ip netip.Addr, port uint16, return ip, port, protocol, nil } -var ( - errPostLineFieldsCount = errors.New("post line has not 2 fields as expected") -) +var errPostLineFieldsCount = errors.New("post line has not 2 fields as expected") func extractPort(line string) (port uint16, err error) { fields := strings.Fields(line) diff --git a/internal/openvpn/extract/pem.go b/internal/openvpn/extract/pem.go index c89bf522..5126a0b7 100644 --- a/internal/openvpn/extract/pem.go +++ b/internal/openvpn/extract/pem.go @@ -7,9 +7,7 @@ import ( "fmt" ) -var ( - errPEMDecode = errors.New("cannot decode PEM encoded block") -) +var errPEMDecode = errors.New("cannot decode PEM encoded block") func PEM(b []byte) (encodedData string, err error) { pemBlock, _ := pem.Decode(b) diff --git a/internal/openvpn/extract/read.go b/internal/openvpn/extract/read.go index 9da84948..4552c59f 100644 --- a/internal/openvpn/extract/read.go +++ b/internal/openvpn/extract/read.go @@ -7,7 +7,8 @@ import ( ) func readCustomConfigLines(filepath string) ( - lines []string, err error) { + lines []string, err error, +) { file, err := os.Open(filepath) if err != nil { return nil, err diff --git a/internal/openvpn/logs_test.go b/internal/openvpn/logs_test.go index 6f1c6077..dfb6636f 100644 --- a/internal/openvpn/logs_test.go +++ b/internal/openvpn/logs_test.go @@ -18,31 +18,38 @@ func Test_processLogLine(t *testing.T) { "openvpn unknown": { "message", "message", - levelInfo}, + levelInfo, + }, "openvpn note": { "NOTE: message", "message", - levelInfo}, + levelInfo, + }, "openvpn warning": { "WARNING: message", "message", - levelWarn}, + levelWarn, + }, "openvpn options error": { "Options error: message", "message", - levelError}, + levelError, + }, "openvpn ignored message": { "NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay", "", - levelInfo}, + levelInfo, + }, "openvpn success": { "Initialization Sequence Completed", "Initialization Sequence Completed", - levelInfo}, + levelInfo, + }, "openvpn auth failed": { "AUTH: Received control message: AUTH_FAILED", "AUTH: Received control message: AUTH_FAILED\n\nYour credentials might be wrong 🤨\n\n", - levelError}, + levelError, + }, "TLS key negotiation error": { s: "TLS Error: TLS key negotiation failed to occur within " + "60 seconds (check your network connectivity)", diff --git a/internal/openvpn/openvpn.go b/internal/openvpn/openvpn.go index 14b08d01..e3c8e161 100644 --- a/internal/openvpn/openvpn.go +++ b/internal/openvpn/openvpn.go @@ -14,7 +14,8 @@ type Configurator struct { } func New(logger Infoer, cmder CmdRunStarter, - puid, pgid int) *Configurator { + puid, pgid int, +) *Configurator { return &Configurator{ logger: logger, cmder: cmder, diff --git a/internal/openvpn/pkcs8/algorithms.go b/internal/openvpn/pkcs8/algorithms.go index 018467f8..3514b88a 100644 --- a/internal/openvpn/pkcs8/algorithms.go +++ b/internal/openvpn/pkcs8/algorithms.go @@ -7,15 +7,11 @@ import ( "fmt" ) -var ( - // Algorithm identifiers are listed at - // https://www.ibm.com/docs/en/zos/2.3.0?topic=programming-object-identifiers - oidDESCBC = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 7} //nolint:gochecknoglobals -) +// Algorithm identifiers are listed at +// https://www.ibm.com/docs/en/zos/2.3.0?topic=programming-object-identifiers +var oidDESCBC = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 7} //nolint:gochecknoglobals -var ( - ErrEncryptionAlgorithmNotPBES2 = errors.New("encryption algorithm is not PBES2") -) +var ErrEncryptionAlgorithmNotPBES2 = errors.New("encryption algorithm is not PBES2") type encryptedPrivateKey struct { EncryptionAlgorithm pkix.AlgorithmIdentifier @@ -28,7 +24,8 @@ type encryptedAlgorithmParams struct { } func getEncryptionAlgorithmOid(der []byte) ( - encryptionSchemeAlgorithm asn1.ObjectIdentifier, err error) { + encryptionSchemeAlgorithm asn1.ObjectIdentifier, err error, +) { var encryptedPrivateKeyData encryptedPrivateKey _, err = asn1.Unmarshal(der, &encryptedPrivateKeyData) if err != nil { diff --git a/internal/openvpn/pkcs8/upgrade.go b/internal/openvpn/pkcs8/upgrade.go index 54693f2a..2b0b9664 100644 --- a/internal/openvpn/pkcs8/upgrade.go +++ b/internal/openvpn/pkcs8/upgrade.go @@ -8,9 +8,7 @@ import ( pkcs8lib "github.com/youmark/pkcs8" ) -var ( - ErrUnsupportedKeyType = errors.New("unsupported key type") -) +var ErrUnsupportedKeyType = errors.New("unsupported key type") // UpgradeEncryptedKey eventually upgrades an encrypted key to a newer encryption // if its encryption is too weak for Openvpn/Openssl. diff --git a/internal/openvpn/run.go b/internal/openvpn/run.go index a8ad7762..fde49606 100644 --- a/internal/openvpn/run.go +++ b/internal/openvpn/run.go @@ -13,7 +13,8 @@ type Runner struct { } func NewRunner(settings settings.OpenVPN, starter CmdStarter, - logger Logger) *Runner { + logger Logger, +) *Runner { return &Runner{ starter: starter, logger: logger, diff --git a/internal/openvpn/start.go b/internal/openvpn/start.go index 8eedda7b..96536f2c 100644 --- a/internal/openvpn/start.go +++ b/internal/openvpn/start.go @@ -18,7 +18,8 @@ const ( ) func start(ctx context.Context, starter CmdStarter, version string, flags []string) ( - stdoutLines, stderrLines <-chan string, waitError <-chan error, err error) { + stdoutLines, stderrLines <-chan string, waitError <-chan error, err error, +) { var bin string switch version { case openvpn.Openvpn25: diff --git a/internal/openvpn/stream.go b/internal/openvpn/stream.go index dba63b91..a6c6883e 100644 --- a/internal/openvpn/stream.go +++ b/internal/openvpn/stream.go @@ -7,7 +7,8 @@ import ( func streamLines(ctx context.Context, done chan<- struct{}, logger Logger, stdout, stderr <-chan string, - tunnelReady chan<- struct{}) { + tunnelReady chan<- struct{}, +) { defer close(done) var line string diff --git a/internal/portforward/loop.go b/internal/portforward/loop.go index 9b400e3d..2029d276 100644 --- a/internal/portforward/loop.go +++ b/internal/portforward/loop.go @@ -34,7 +34,8 @@ type Loop struct { func NewLoop(settings settings.PortForwarding, routing Routing, client *http.Client, portAllower PortAllower, - logger Logger, uid, gid int) *Loop { + logger Logger, uid, gid int, +) *Loop { return &Loop{ settings: Settings{ VPNIsUp: ptrTo(false), @@ -75,7 +76,8 @@ func (l *Loop) Start(_ context.Context) (runError <-chan error, _ error) { func (l *Loop) run(runCtx context.Context, runDone chan<- struct{}, runErrorCh chan<- error, updateTrigger <-chan Settings, - updateResult chan<- error) { + updateResult chan<- error, +) { defer close(runDone) var serviceRunError <-chan error diff --git a/internal/portforward/service/fs.go b/internal/portforward/service/fs.go index 11d7d67c..cc389fed 100644 --- a/internal/portforward/service/fs.go +++ b/internal/portforward/service/fs.go @@ -15,7 +15,7 @@ func (s *Service) writePortForwardedFile(ports []uint16) (err error) { filepath := s.settings.Filepath s.logger.Info("writing port file " + filepath) - const perms = os.FileMode(0644) + const perms = os.FileMode(0o644) err = os.WriteFile(filepath, fileData, perms) if err != nil { return fmt.Errorf("writing file: %w", err) diff --git a/internal/portforward/service/service.go b/internal/portforward/service/service.go index 081b54d2..077e027e 100644 --- a/internal/portforward/service/service.go +++ b/internal/portforward/service/service.go @@ -26,7 +26,8 @@ type Service struct { } func New(settings Settings, routing Routing, client *http.Client, - portAllower PortAllower, logger Logger, puid, pgid int) *Service { + portAllower PortAllower, logger Logger, puid, pgid int, +) *Service { return &Service{ // Fixed parameters settings: settings, diff --git a/internal/portforward/service/start.go b/internal/portforward/service/start.go index e8f1d017..0f270c23 100644 --- a/internal/portforward/service/start.go +++ b/internal/portforward/service/start.go @@ -82,7 +82,8 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, err error) readyCh := make(chan struct{}) go func(ctx context.Context, portForwarder PortForwarder, obj utils.PortForwardObjects, readyCh chan<- struct{}, - runError chan<- error, doneCh chan<- struct{}) { + runError chan<- error, doneCh chan<- struct{}, + ) { defer close(doneCh) close(readyCh) err = portForwarder.KeepPortForward(ctx, obj) diff --git a/internal/portforward/settings.go b/internal/portforward/settings.go index 02103cad..df8ccb13 100644 --- a/internal/portforward/settings.go +++ b/internal/portforward/settings.go @@ -18,7 +18,8 @@ type Settings struct { // and returns them if they are valid, or returns an error otherwise. // In all cases, the receiving settings are unmodified. func (s Settings) updateWith(partialUpdate Settings, - forStartup bool) (updated Settings, err error) { + forStartup bool, +) (updated Settings, err error) { updated = s.copy() updated.overrideWith(partialUpdate) err = updated.validate(forStartup) diff --git a/internal/provider/airvpn/connection.go b/internal/provider/airvpn/connection.go index 72c0471b..6faa4f68 100644 --- a/internal/provider/airvpn/connection.go +++ b/internal/provider/airvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 1637) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/airvpn/openvpnconf.go b/internal/provider/airvpn/openvpnconf.go index 6c4658d1..e59e775c 100644 --- a/internal/provider/airvpn/openvpnconf.go +++ b/internal/provider/airvpn/openvpnconf.go @@ -10,7 +10,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { const defaultMTU = 1320 // see https://github.com/qdm12/gluetun/issues/1650#issuecomment-1988298206 const defaultMSSFix = defaultMTU - 28 // 28 bytes of IPv4 UDP header size providerSettings := utils.OpenVPNProviderSettings{ @@ -31,7 +32,8 @@ func (p *Provider) OpenVPNConfig(connection models.Connection, providerSettings.Ciphers = []string{ openvpn.AES256gcm, openvpn.AES256cbc, openvpn.AES192gcm, openvpn.AES192cbc, openvpn.AES128gcm, openvpn.AES128cbc, - openvpn.Chacha20Poly1305} + openvpn.Chacha20Poly1305, + } default: panic(fmt.Sprintf("openvpn version %q is not implemented", settings.Version)) } diff --git a/internal/provider/airvpn/provider.go b/internal/provider/airvpn/provider.go index 1e2f76dd..377506ec 100644 --- a/internal/provider/airvpn/provider.go +++ b/internal/provider/airvpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - client *http.Client) *Provider { + client *http.Client, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/airvpn/updater/api.go b/internal/provider/airvpn/updater/api.go index 9639f793..e5596d8f 100644 --- a/internal/provider/airvpn/updater/api.go +++ b/internal/provider/airvpn/updater/api.go @@ -32,7 +32,8 @@ type apiServer struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { const url = "https://airvpn.org/api/status/" request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) diff --git a/internal/provider/airvpn/updater/servers.go b/internal/provider/airvpn/updater/servers.go index ff2e2122..d5105e1a 100644 --- a/internal/provider/airvpn/updater/servers.go +++ b/internal/provider/airvpn/updater/servers.go @@ -13,7 +13,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { data, err := fetchAPI(ctx, u.client) if err != nil { return nil, fmt.Errorf("fetching API: %w", err) diff --git a/internal/provider/common/portforward.go b/internal/provider/common/portforward.go index 5444b4a5..db1385af 100644 --- a/internal/provider/common/portforward.go +++ b/internal/provider/common/portforward.go @@ -2,6 +2,4 @@ package common import "errors" -var ( - ErrPortForwardNotSupported = errors.New("port forwarding not supported") -) +var ErrPortForwardNotSupported = errors.New("port forwarding not supported") diff --git a/internal/provider/custom/connection.go b/internal/provider/custom/connection.go index 7ca057f5..92c73538 100644 --- a/internal/provider/custom/connection.go +++ b/internal/provider/custom/connection.go @@ -10,13 +10,12 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -var ( - ErrVPNTypeNotSupported = errors.New("VPN type not supported for custom provider") -) +var ErrVPNTypeNotSupported = errors.New("VPN type not supported for custom provider") // GetConnection gets the connection from the OpenVPN configuration file. func (p *Provider) GetConnection(selection settings.ServerSelection, _ bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { switch selection.VPN { case vpn.OpenVPN: return getOpenVPNConnection(p.extractor, selection) @@ -29,7 +28,8 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, _ bool) ( func getOpenVPNConnection(extractor Extractor, selection settings.ServerSelection) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { _, connection, err = extractor.Data(*selection.OpenVPN.ConfFile) if err != nil { return connection, fmt.Errorf("extracting connection: %w", err) @@ -52,7 +52,8 @@ func getOpenVPNConnection(extractor Extractor, } func getWireguardConnection(selection settings.ServerSelection) ( - connection models.Connection) { + connection models.Connection, +) { connection = models.Connection{ Type: vpn.Wireguard, IP: selection.Wireguard.EndpointIP, diff --git a/internal/provider/custom/openvpnconf.go b/internal/provider/custom/openvpnconf.go index 2639804d..934996ac 100644 --- a/internal/provider/custom/openvpnconf.go +++ b/internal/provider/custom/openvpnconf.go @@ -15,7 +15,8 @@ import ( var ErrExtractData = errors.New("failed extracting information from custom configuration file") func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { lines, _, err := p.extractor.Data(*settings.ConfFile) if err != nil { // Configuration file is already validated in settings validation in @@ -30,7 +31,8 @@ func (p *Provider) OpenVPNConfig(connection models.Connection, } func modifyConfig(lines []string, connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (modified []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (modified []string) { // Remove some lines for _, line := range lines { switch { diff --git a/internal/provider/cyberghost/connection.go b/internal/provider/cyberghost/connection.go index 2a58d2ad..c3feb1ee 100644 --- a/internal/provider/cyberghost/connection.go +++ b/internal/provider/cyberghost/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/cyberghost/openvpnconf.go b/internal/provider/cyberghost/openvpnconf.go index 8302b58c..ad93784b 100644 --- a/internal/provider/cyberghost/openvpnconf.go +++ b/internal/provider/cyberghost/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/cyberghost/provider.go b/internal/provider/cyberghost/provider.go index 4fcaf27f..f8bee0ea 100644 --- a/internal/provider/cyberghost/provider.go +++ b/internal/provider/cyberghost/provider.go @@ -15,7 +15,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/cyberghost/updater/servers.go b/internal/provider/cyberghost/updater/servers.go index b82efc8c..d7ed0a24 100644 --- a/internal/provider/cyberghost/updater/servers.go +++ b/internal/provider/cyberghost/updater/servers.go @@ -10,7 +10,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { possibleServers := getPossibleServers() possibleHosts := possibleServers.hostsSlice() diff --git a/internal/provider/example/connection.go b/internal/provider/example/connection.go index 68b74713..9f529291 100644 --- a/internal/provider/example/connection.go +++ b/internal/provider/example/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { // TODO: Set the default ports for each VPN protocol+network protocol // combination. If one combination is not supported, set it to `0`. defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd diff --git a/internal/provider/example/openvpnconf.go b/internal/provider/example/openvpnconf.go index 4ad238e6..fb49710c 100644 --- a/internal/provider/example/openvpnconf.go +++ b/internal/provider/example/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { // TODO: Set the necessary fields in `providerSettings` to // generate the right OpenVPN configuration file. //nolint:mnd diff --git a/internal/provider/example/provider.go b/internal/provider/example/provider.go index 416a1c41..020a1b42 100644 --- a/internal/provider/example/provider.go +++ b/internal/provider/example/provider.go @@ -18,7 +18,8 @@ type Provider struct { // TODO: remove unneeded arguments once the updater is implemented. func New(storage common.Storage, randSource rand.Source, updaterWarner common.Warner, client *http.Client, - unzipper common.Unzipper, parallelResolver common.ParallelResolver) *Provider { + unzipper common.Unzipper, parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/example/updater/api.go b/internal/provider/example/updater/api.go index ed6bf718..4087db30 100644 --- a/internal/provider/example/updater/api.go +++ b/internal/provider/example/updater/api.go @@ -8,9 +8,7 @@ import ( "net/http" ) -var ( - errHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var errHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type apiData struct { Servers []apiServer `json:"servers"` @@ -26,7 +24,8 @@ type apiServer struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { // TODO: adapt this URL and the structures above to match the real // API models you have. const url = "https://example.com/servers" diff --git a/internal/provider/example/updater/servers.go b/internal/provider/example/updater/servers.go index 4e4689d6..8e38e765 100644 --- a/internal/provider/example/updater/servers.go +++ b/internal/provider/example/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { // FetchServers obtains information for each VPN server // for the VPN service provider. // diff --git a/internal/provider/example/updater/updater.go b/internal/provider/example/updater/updater.go index 496ac31a..a3abfbdb 100644 --- a/internal/provider/example/updater/updater.go +++ b/internal/provider/example/updater/updater.go @@ -15,7 +15,8 @@ type Updater struct { } func New(warner common.Warner, unzipper common.Unzipper, - client *http.Client, parallelResolver common.ParallelResolver) *Updater { + client *http.Client, parallelResolver common.ParallelResolver, +) *Updater { // TODO: remove arguments not used by the updater return &Updater{ client: client, diff --git a/internal/provider/expressvpn/connection.go b/internal/provider/expressvpn/connection.go index 02fab186..5893ec0c 100644 --- a/internal/provider/expressvpn/connection.go +++ b/internal/provider/expressvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(0, 1195, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/expressvpn/openvpnconf.go b/internal/provider/expressvpn/openvpnconf.go index 68981ef7..8294a111 100644 --- a/internal/provider/expressvpn/openvpnconf.go +++ b/internal/provider/expressvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/expressvpn/provider.go b/internal/provider/expressvpn/provider.go index 3fddc69b..de55d2b3 100644 --- a/internal/provider/expressvpn/provider.go +++ b/internal/provider/expressvpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/expressvpn/updater/servers.go b/internal/provider/expressvpn/updater/servers.go index 0aef3a1a..eed1b8a9 100644 --- a/internal/provider/expressvpn/updater/servers.go +++ b/internal/provider/expressvpn/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { servers = hardcodedServers() hosts := make([]string, len(servers)) diff --git a/internal/provider/expressvpn/updater/updater.go b/internal/provider/expressvpn/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/expressvpn/updater/updater.go +++ b/internal/provider/expressvpn/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/fastestvpn/connection.go b/internal/provider/fastestvpn/connection.go index 6e6ff482..f927e050 100644 --- a/internal/provider/fastestvpn/connection.go +++ b/internal/provider/fastestvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(4443, 4443, 51820) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/fastestvpn/openvpnconf.go b/internal/provider/fastestvpn/openvpnconf.go index 9367316d..c6a9be7e 100644 --- a/internal/provider/fastestvpn/openvpnconf.go +++ b/internal/provider/fastestvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/fastestvpn/provider.go b/internal/provider/fastestvpn/provider.go index 497aa2e1..d804894b 100644 --- a/internal/provider/fastestvpn/provider.go +++ b/internal/provider/fastestvpn/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/fastestvpn/updater/api.go b/internal/provider/fastestvpn/updater/api.go index f0d02be9..6776d120 100644 --- a/internal/provider/fastestvpn/updater/api.go +++ b/internal/provider/fastestvpn/updater/api.go @@ -19,16 +19,15 @@ type apiServer struct { hostname string } -var ( - ErrDataMalformed = errors.New("data is malformed") -) +var ErrDataMalformed = errors.New("data is malformed") const apiURL = "https://support.fastestvpn.com/wp-admin/admin-ajax.php" // The API URL and requests are shamelessly taken from network operations // done on the page https://support.fastestvpn.com/vpn-servers/ func fetchAPIServers(ctx context.Context, client *http.Client, protocol string) ( - servers []apiServer, err error) { + servers []apiServer, err error, +) { form := url.Values{ "action": []string{"vpn_servers"}, "protocol": []string{protocol}, diff --git a/internal/provider/fastestvpn/updater/servers.go b/internal/provider/fastestvpn/updater/servers.go index b6f9d04f..0401ab35 100644 --- a/internal/provider/fastestvpn/updater/servers.go +++ b/internal/provider/fastestvpn/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { protocols := []string{"ikev2", "tcp", "udp"} hts := make(hostToServerData) diff --git a/internal/provider/fastestvpn/updater/updater.go b/internal/provider/fastestvpn/updater/updater.go index f15a2f3a..df4427cc 100644 --- a/internal/provider/fastestvpn/updater/updater.go +++ b/internal/provider/fastestvpn/updater/updater.go @@ -13,7 +13,8 @@ type Updater struct { } func New(client *http.Client, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, parallelResolver: parallelResolver, diff --git a/internal/provider/giganews/connection.go b/internal/provider/giganews/connection.go index fef88a9b..13a9ae43 100644 --- a/internal/provider/giganews/connection.go +++ b/internal/provider/giganews/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/giganews/openvpnconf.go b/internal/provider/giganews/openvpnconf.go index 93d1e1db..30c2ea7d 100644 --- a/internal/provider/giganews/openvpnconf.go +++ b/internal/provider/giganews/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/giganews/provider.go b/internal/provider/giganews/provider.go index eef31214..99a5afba 100644 --- a/internal/provider/giganews/provider.go +++ b/internal/provider/giganews/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/giganews/updater/servers.go b/internal/provider/giganews/updater/servers.go index 0746bb00..c75085ec 100644 --- a/internal/provider/giganews/updater/servers.go +++ b/internal/provider/giganews/updater/servers.go @@ -12,7 +12,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://support.vyprvpn.com/hc/article_attachments/360052617332/Vypr_OpenVPN_20200320.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/giganews/updater/updater.go b/internal/provider/giganews/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/giganews/updater/updater.go +++ b/internal/provider/giganews/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/hidemyass/connection.go b/internal/provider/hidemyass/connection.go index d949b9fa..856d8db0 100644 --- a/internal/provider/hidemyass/connection.go +++ b/internal/provider/hidemyass/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(8080, 553, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/hidemyass/openvpnconf.go b/internal/provider/hidemyass/openvpnconf.go index 05e75e46..a2ba4e4e 100644 --- a/internal/provider/hidemyass/openvpnconf.go +++ b/internal/provider/hidemyass/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/hidemyass/provider.go b/internal/provider/hidemyass/provider.go index ca6dd015..cc778d16 100644 --- a/internal/provider/hidemyass/provider.go +++ b/internal/provider/hidemyass/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/hidemyass/updater/hosts.go b/internal/provider/hidemyass/updater/hosts.go index 4591b083..22fcbd0a 100644 --- a/internal/provider/hidemyass/updater/hosts.go +++ b/internal/provider/hidemyass/updater/hosts.go @@ -1,7 +1,8 @@ package updater func getUniqueHosts(tcpHostToURL, udpHostToURL map[string]string) ( - hosts []string) { + hosts []string, +) { uniqueHosts := make(map[string]struct{}, len(tcpHostToURL)) for host := range tcpHostToURL { uniqueHosts[host] = struct{}{} diff --git a/internal/provider/hidemyass/updater/hosttourl.go b/internal/provider/hidemyass/updater/hosttourl.go index 486234e8..3e0c09de 100644 --- a/internal/provider/hidemyass/updater/hosttourl.go +++ b/internal/provider/hidemyass/updater/hosttourl.go @@ -9,7 +9,8 @@ import ( ) func getAllHostToURL(ctx context.Context, client *http.Client) ( - tcpHostToURL, udpHostToURL map[string]string, err error) { + tcpHostToURL, udpHostToURL map[string]string, err error, +) { tcpHostToURL, err = getHostToURL(ctx, client, "TCP") if err != nil { return nil, nil, err @@ -24,7 +25,8 @@ func getAllHostToURL(ctx context.Context, client *http.Client) ( } func getHostToURL(ctx context.Context, client *http.Client, protocol string) ( - hostToURL map[string]string, err error) { + hostToURL map[string]string, err error, +) { const baseURL = "https://vpn.hidemyass.com/vpn-config" indexURL := baseURL + "/" + strings.ToUpper(protocol) + "/" diff --git a/internal/provider/hidemyass/updater/index.go b/internal/provider/hidemyass/updater/index.go index 88950286..6829baaf 100644 --- a/internal/provider/hidemyass/updater/index.go +++ b/internal/provider/hidemyass/updater/index.go @@ -11,7 +11,8 @@ import ( var indexOpenvpnLinksRegex = regexp.MustCompile(`.+\.ovpn`) func fetchIndex(ctx context.Context, client *http.Client, indexURL string) ( - openvpnURLs []string, err error) { + openvpnURLs []string, err error, +) { request, err := http.NewRequestWithContext(ctx, http.MethodGet, indexURL, nil) if err != nil { return nil, err diff --git a/internal/provider/hidemyass/updater/servers.go b/internal/provider/hidemyass/updater/servers.go index 8b6d8306..83a765a3 100644 --- a/internal/provider/hidemyass/updater/servers.go +++ b/internal/provider/hidemyass/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { tcpHostToURL, udpHostToURL, err := getAllHostToURL(ctx, u.client) if err != nil { return nil, err diff --git a/internal/provider/hidemyass/updater/updater.go b/internal/provider/hidemyass/updater/updater.go index f15a2f3a..df4427cc 100644 --- a/internal/provider/hidemyass/updater/updater.go +++ b/internal/provider/hidemyass/updater/updater.go @@ -13,7 +13,8 @@ type Updater struct { } func New(client *http.Client, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, parallelResolver: parallelResolver, diff --git a/internal/provider/ipvanish/connection.go b/internal/provider/ipvanish/connection.go index d90fecb2..e66e9ece 100644 --- a/internal/provider/ipvanish/connection.go +++ b/internal/provider/ipvanish/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/ipvanish/openvpnconf.go b/internal/provider/ipvanish/openvpnconf.go index 03c194b4..d3dfc1b4 100644 --- a/internal/provider/ipvanish/openvpnconf.go +++ b/internal/provider/ipvanish/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, Ciphers: []string{ diff --git a/internal/provider/ipvanish/provider.go b/internal/provider/ipvanish/provider.go index ece3aad1..c00dcdc6 100644 --- a/internal/provider/ipvanish/provider.go +++ b/internal/provider/ipvanish/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/ipvanish/updater/filename.go b/internal/provider/ipvanish/updater/filename.go index fde6e6d6..f95e386f 100644 --- a/internal/provider/ipvanish/updater/filename.go +++ b/internal/provider/ipvanish/updater/filename.go @@ -12,7 +12,8 @@ import ( var errCountryCodeUnknown = errors.New("country code is unknown") func parseFilename(fileName, hostname string, titleCaser cases.Caser) ( - country, city string, err error) { + country, city string, err error, +) { const prefix = "ipvanish-" s := strings.TrimPrefix(fileName, prefix) diff --git a/internal/provider/ipvanish/updater/servers.go b/internal/provider/ipvanish/updater/servers.go index 3f5e8814..096a12e4 100644 --- a/internal/provider/ipvanish/updater/servers.go +++ b/internal/provider/ipvanish/updater/servers.go @@ -14,7 +14,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://configs.ipvanish.com/configs/configs.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/ipvanish/updater/updater.go b/internal/provider/ipvanish/updater/updater.go index 223cb0ed..c2f9d7f2 100644 --- a/internal/provider/ipvanish/updater/updater.go +++ b/internal/provider/ipvanish/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, warner: warner, diff --git a/internal/provider/ivpn/connection.go b/internal/provider/ivpn/connection.go index 0633467f..85558f69 100644 --- a/internal/provider/ivpn/connection.go +++ b/internal/provider/ivpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 58237) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/ivpn/openvpnconf.go b/internal/provider/ivpn/openvpnconf.go index 6578eded..57edfd7b 100644 --- a/internal/provider/ivpn/openvpnconf.go +++ b/internal/provider/ivpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/ivpn/provider.go b/internal/provider/ivpn/provider.go index 3792eeb4..1bee35aa 100644 --- a/internal/provider/ivpn/provider.go +++ b/internal/provider/ivpn/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/ivpn/updater/api.go b/internal/provider/ivpn/updater/api.go index b7ebb5d4..54d8d5d9 100644 --- a/internal/provider/ivpn/updater/api.go +++ b/internal/provider/ivpn/updater/api.go @@ -8,9 +8,7 @@ import ( "net/http" ) -var ( - errHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var errHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type apiData struct { Servers []apiServer `json:"servers"` @@ -31,7 +29,8 @@ type apiHostnames struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { const url = "https://api.ivpn.net/v4/servers/stats" request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) diff --git a/internal/provider/ivpn/updater/servers.go b/internal/provider/ivpn/updater/servers.go index 62919ce5..33c2abe9 100644 --- a/internal/provider/ivpn/updater/servers.go +++ b/internal/provider/ivpn/updater/servers.go @@ -12,7 +12,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { data, err := fetchAPI(ctx, u.client) if err != nil { return nil, fmt.Errorf("fetching API: %w", err) diff --git a/internal/provider/ivpn/updater/servers_test.go b/internal/provider/ivpn/updater/servers_test.go index 1516eead..68a709e3 100644 --- a/internal/provider/ivpn/updater/servers_test.go +++ b/internal/provider/ivpn/updater/servers_test.go @@ -116,17 +116,23 @@ func Test_Updater_GetServers(t *testing.T) { }, resolveWarnings: []string{"resolve warning"}, servers: []models.Server{ - {VPN: vpn.OpenVPN, Country: "Country1", + { + VPN: vpn.OpenVPN, Country: "Country1", City: "City A", Hostname: "hosta", TCP: true, UDP: true, - IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1}), netip.AddrFrom4([4]byte{2, 2, 2, 2})}}, - {VPN: vpn.OpenVPN, Country: "Country2", + IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1}), netip.AddrFrom4([4]byte{2, 2, 2, 2})}, + }, + { + VPN: vpn.OpenVPN, Country: "Country2", City: "City B", Hostname: "hostb", TCP: true, UDP: true, - IPs: []netip.Addr{netip.AddrFrom4([4]byte{3, 3, 3, 3}), netip.AddrFrom4([4]byte{4, 4, 4, 4})}}, - {VPN: vpn.Wireguard, + IPs: []netip.Addr{netip.AddrFrom4([4]byte{3, 3, 3, 3}), netip.AddrFrom4([4]byte{4, 4, 4, 4})}, + }, + { + VPN: vpn.Wireguard, Country: "Country3", City: "City C", Hostname: "hostc", WgPubKey: "xyz", - IPs: []netip.Addr{netip.AddrFrom4([4]byte{5, 5, 5, 5}), netip.AddrFrom4([4]byte{6, 6, 6, 6})}}, + IPs: []netip.Addr{netip.AddrFrom4([4]byte{5, 5, 5, 5}), netip.AddrFrom4([4]byte{6, 6, 6, 6})}, + }, }, }, } diff --git a/internal/provider/ivpn/updater/updater.go b/internal/provider/ivpn/updater/updater.go index f15a2f3a..df4427cc 100644 --- a/internal/provider/ivpn/updater/updater.go +++ b/internal/provider/ivpn/updater/updater.go @@ -13,7 +13,8 @@ type Updater struct { } func New(client *http.Client, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, parallelResolver: parallelResolver, diff --git a/internal/provider/mullvad/connection.go b/internal/provider/mullvad/connection.go index f01ed783..5a25c5e8 100644 --- a/internal/provider/mullvad/connection.go +++ b/internal/provider/mullvad/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/mullvad/openvpnconf.go b/internal/provider/mullvad/openvpnconf.go index 6ddfffcc..b6d3d63c 100644 --- a/internal/provider/mullvad/openvpnconf.go +++ b/internal/provider/mullvad/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/mullvad/provider.go b/internal/provider/mullvad/provider.go index ab08c94c..45e927e6 100644 --- a/internal/provider/mullvad/provider.go +++ b/internal/provider/mullvad/provider.go @@ -16,7 +16,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - client *http.Client) *Provider { + client *http.Client, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/mullvad/updater/servers.go b/internal/provider/mullvad/updater/servers.go index f0175729..b6587b10 100644 --- a/internal/provider/mullvad/updater/servers.go +++ b/internal/provider/mullvad/updater/servers.go @@ -10,7 +10,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { data, err := fetchAPI(ctx, u.client) if err != nil { return nil, err diff --git a/internal/provider/nordvpn/connection.go b/internal/provider/nordvpn/connection.go index ad4ed28f..3e475141 100644 --- a/internal/provider/nordvpn/connection.go +++ b/internal/provider/nordvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/nordvpn/openvpnconf.go b/internal/provider/nordvpn/openvpnconf.go index e5f721ba..58c7c865 100644 --- a/internal/provider/nordvpn/openvpnconf.go +++ b/internal/provider/nordvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/nordvpn/provider.go b/internal/provider/nordvpn/provider.go index c9ddf1ef..fd885b27 100644 --- a/internal/provider/nordvpn/provider.go +++ b/internal/provider/nordvpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - client *http.Client, updaterWarner common.Warner) *Provider { + client *http.Client, updaterWarner common.Warner, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/nordvpn/updater/api.go b/internal/provider/nordvpn/updater/api.go index 26c29164..3d122a8e 100644 --- a/internal/provider/nordvpn/updater/api.go +++ b/internal/provider/nordvpn/updater/api.go @@ -8,12 +8,11 @@ import ( "net/http" ) -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") func fetchAPI(ctx context.Context, client *http.Client, - limit uint) (data serversData, err error) { + limit uint, +) (data serversData, err error) { url := "https://api.nordvpn.com/v2/servers" url += fmt.Sprintf("?limit=%d", limit) // 0 means no limit diff --git a/internal/provider/nordvpn/updater/models.go b/internal/provider/nordvpn/updater/models.go index bc531100..ea2296b2 100644 --- a/internal/provider/nordvpn/updater/models.go +++ b/internal/provider/nordvpn/updater/models.go @@ -175,7 +175,8 @@ var ( // wireguardPublicKey returns the Wireguard public key for the server. func (s *serverData) wireguardPublicKey(technologies map[uint32]technologyData) ( - wgPubKey string, err error) { + wgPubKey string, err error, +) { for _, technology := range s.Technologies { data, ok := technologies[technology.ID] if !ok || data.Identifier != "wireguard_udp" { diff --git a/internal/provider/nordvpn/updater/servers.go b/internal/provider/nordvpn/updater/servers.go index 82715c72..d939700b 100644 --- a/internal/provider/nordvpn/updater/servers.go +++ b/internal/provider/nordvpn/updater/servers.go @@ -11,12 +11,11 @@ import ( "github.com/qdm12/gluetun/internal/provider/common" ) -var ( - ErrNotIPv4 = errors.New("IP address is not IPv4") -) +var ErrNotIPv4 = errors.New("IP address is not IPv4") func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const limit = 0 data, err := fetchAPI(ctx, u.client, limit) if err != nil { @@ -47,7 +46,8 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( func extractServers(jsonServer serverData, groups map[uint32]groupData, services map[uint32]serviceData, locations map[uint32]locationData, technologies map[uint32]technologyData) (servers []models.Server, - warnings []string) { + warnings []string, +) { ignoreReason := "" switch { case jsonServer.Status != "online": diff --git a/internal/provider/perfectprivacy/connection.go b/internal/provider/perfectprivacy/connection.go index a9dfa6a8..1c019e5f 100644 --- a/internal/provider/perfectprivacy/connection.go +++ b/internal/provider/perfectprivacy/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/perfectprivacy/openvpnconf.go b/internal/provider/perfectprivacy/openvpnconf.go index 235968e5..d225a9bc 100644 --- a/internal/provider/perfectprivacy/openvpnconf.go +++ b/internal/provider/perfectprivacy/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/perfectprivacy/portforward.go b/internal/provider/perfectprivacy/portforward.go index fc0f0f5c..9716ab01 100644 --- a/internal/provider/perfectprivacy/portforward.go +++ b/internal/provider/perfectprivacy/portforward.go @@ -9,7 +9,8 @@ import ( // PortForward calculates and returns the VPN server side ports forwarded. func (p *Provider) PortForward(_ context.Context, - objects utils.PortForwardObjects) (ports []uint16, err error) { + objects utils.PortForwardObjects, +) (ports []uint16, err error) { if !objects.InternalIP.IsValid() { panic("internal ip is not set") } @@ -18,7 +19,8 @@ func (p *Provider) PortForward(_ context.Context, } func (p *Provider) KeepPortForward(ctx context.Context, - _ utils.PortForwardObjects) (err error) { + _ utils.PortForwardObjects, +) (err error) { <-ctx.Done() return ctx.Err() } diff --git a/internal/provider/perfectprivacy/provider.go b/internal/provider/perfectprivacy/provider.go index 198a148f..5ca1b4d9 100644 --- a/internal/provider/perfectprivacy/provider.go +++ b/internal/provider/perfectprivacy/provider.go @@ -15,7 +15,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - unzipper common.Unzipper, updaterWarner common.Warner) *Provider { + unzipper common.Unzipper, updaterWarner common.Warner, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/perfectprivacy/updater/servers.go b/internal/provider/perfectprivacy/updater/servers.go index 161f7d6e..ea79e54c 100644 --- a/internal/provider/perfectprivacy/updater/servers.go +++ b/internal/provider/perfectprivacy/updater/servers.go @@ -13,7 +13,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { zipURL := url.URL{ Scheme: "https", Host: "www.perfect-privacy.com", @@ -53,7 +54,8 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } func addServerFromOvpn(cts cityToServer, - fileName string, content []byte) (err error) { + fileName string, content []byte, +) (err error) { if !strings.HasSuffix(fileName, ".conf") { return nil // not an OpenVPN file } diff --git a/internal/provider/privado/connection.go b/internal/provider/privado/connection.go index bbc3dff3..8e5387ed 100644 --- a/internal/provider/privado/connection.go +++ b/internal/provider/privado/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(0, 1194, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/privado/openvpnconf.go b/internal/provider/privado/openvpnconf.go index 7eed6d7f..70a8cc62 100644 --- a/internal/provider/privado/openvpnconf.go +++ b/internal/provider/privado/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ AuthUserPass: true, diff --git a/internal/provider/privado/provider.go b/internal/provider/privado/provider.go index 38f9e827..1abca4c0 100644 --- a/internal/provider/privado/provider.go +++ b/internal/provider/privado/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, ipFetcher common.IPFetcher, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/privado/updater/servers.go b/internal/provider/privado/updater/servers.go index 5fadb604..2d15f1ec 100644 --- a/internal/provider/privado/updater/servers.go +++ b/internal/provider/privado/updater/servers.go @@ -12,7 +12,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://privadovpn.com/apps/ovpn_configs.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/privado/updater/updater.go b/internal/provider/privado/updater/updater.go index 65ee9cfe..2136f8ee 100644 --- a/internal/provider/privado/updater/updater.go +++ b/internal/provider/privado/updater/updater.go @@ -12,7 +12,8 @@ type Updater struct { } func New(ipFetcher common.IPFetcher, unzipper common.Unzipper, - warner common.Warner, parallelResolver common.ParallelResolver) *Updater { + warner common.Warner, parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ ipFetcher: ipFetcher, unzipper: unzipper, diff --git a/internal/provider/privateinternetaccess/connection.go b/internal/provider/privateinternetaccess/connection.go index 1f06fa2a..5ff07ecc 100644 --- a/internal/provider/privateinternetaccess/connection.go +++ b/internal/provider/privateinternetaccess/connection.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { // Set port defaults depending on encryption preset. var defaults utils.ConnectionDefaults switch *selection.OpenVPN.PIAEncPreset { diff --git a/internal/provider/privateinternetaccess/openvpnconf.go b/internal/provider/privateinternetaccess/openvpnconf.go index 702c3df4..62c6ef44 100644 --- a/internal/provider/privateinternetaccess/openvpnconf.go +++ b/internal/provider/privateinternetaccess/openvpnconf.go @@ -9,7 +9,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, RenegDisabled: true, diff --git a/internal/provider/privateinternetaccess/portforward.go b/internal/provider/privateinternetaccess/portforward.go index 4af365dc..b36fce10 100644 --- a/internal/provider/privateinternetaccess/portforward.go +++ b/internal/provider/privateinternetaccess/portforward.go @@ -21,13 +21,12 @@ import ( "github.com/qdm12/gluetun/internal/provider/utils" ) -var ( - ErrServerNameNotFound = errors.New("server name not found in servers") -) +var ErrServerNameNotFound = errors.New("server name not found in servers") // PortForward obtains a VPN server side port forwarded from PIA. func (p *Provider) PortForward(ctx context.Context, - objects utils.PortForwardObjects) (ports []uint16, err error) { + objects utils.PortForwardObjects, +) (ports []uint16, err error) { switch { case objects.ServerName == "": panic("server name cannot be empty") @@ -88,12 +87,11 @@ func (p *Provider) PortForward(ctx context.Context, return []uint16{data.Port}, nil } -var ( - ErrPortForwardedExpired = errors.New("port forwarded data expired") -) +var ErrPortForwardedExpired = errors.New("port forwarded data expired") func (p *Provider) KeepPortForward(ctx context.Context, - objects utils.PortForwardObjects) (err error) { + objects utils.PortForwardObjects, +) (err error) { switch { case objects.ServerName == "": panic("server name cannot be empty") @@ -154,7 +152,8 @@ func buildAPIIPAddress(gateway netip.Addr) (api netip.Addr) { } func refreshPIAPortForwardData(ctx context.Context, client, privateIPClient *http.Client, - apiIP netip.Addr, portForwardPath, username, password string) (data piaPortForwardData, err error) { + apiIP netip.Addr, portForwardPath, username, password string, +) (data piaPortForwardData, err error) { data.Token, err = fetchToken(ctx, client, username, password) if err != nil { return data, fmt.Errorf("fetching token: %w", err) @@ -203,7 +202,7 @@ func readPIAPortForwardData(portForwardPath string) (data piaPortForwardData, er } func writePIAPortForwardData(portForwardPath string, data piaPortForwardData) (err error) { - const permission = fs.FileMode(0644) + const permission = fs.FileMode(0o644) file, err := os.OpenFile(portForwardPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, permission) if err != nil { return err @@ -251,12 +250,11 @@ func packPayload(port uint16, token string, expiration time.Time) (payload strin return payload, nil } -var ( - errEmptyToken = errors.New("token received is empty") -) +var errEmptyToken = errors.New("token received is empty") func fetchToken(ctx context.Context, client *http.Client, - username, password string) (token string, err error) { + username, password string, +) (token string, err error) { errSubstitutions := map[string]string{ url.QueryEscape(username): "", url.QueryEscape(password): "", @@ -302,7 +300,8 @@ func fetchToken(ctx context.Context, client *http.Client, } func fetchPortForwardData(ctx context.Context, client *http.Client, apiIP netip.Addr, token string) ( - port uint16, signature string, expiration time.Time, err error) { + port uint16, signature string, expiration time.Time, err error, +) { errSubstitutions := map[string]string{url.QueryEscape(token): ""} queryParams := make(url.Values) @@ -351,9 +350,7 @@ func fetchPortForwardData(ctx context.Context, client *http.Client, apiIP netip. return port, data.Signature, expiration, err } -var ( - ErrBadResponse = errors.New("bad response received") -) +var ErrBadResponse = errors.New("bad response received") func bindPort(ctx context.Context, client *http.Client, apiIPAddress netip.Addr, data piaPortForwardData) (err error) { payload, err := packPayload(data.Port, data.Token, data.Expiration) diff --git a/internal/provider/privateinternetaccess/provider.go b/internal/provider/privateinternetaccess/provider.go index 6d342c2b..eeb5b549 100644 --- a/internal/provider/privateinternetaccess/provider.go +++ b/internal/provider/privateinternetaccess/provider.go @@ -20,7 +20,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - timeNow func() time.Time, client *http.Client) *Provider { + timeNow func() time.Time, client *http.Client, +) *Provider { const jsonPortForwardPath = "/gluetun/piaportforward.json" return &Provider{ storage: storage, diff --git a/internal/provider/privateinternetaccess/updater/api.go b/internal/provider/privateinternetaccess/updater/api.go index 490fbc0e..d08fb1d9 100644 --- a/internal/provider/privateinternetaccess/updater/api.go +++ b/internal/provider/privateinternetaccess/updater/api.go @@ -11,9 +11,7 @@ import ( "net/netip" ) -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type apiData struct { Regions []regionData `json:"regions"` @@ -36,7 +34,8 @@ type serverData struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { const url = "https://serverlist.piaservers.net/vpninfo/servers/v6" request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) diff --git a/internal/provider/privateinternetaccess/updater/hosttoserver.go b/internal/provider/privateinternetaccess/updater/hosttoserver.go index 76cd6efc..93464106 100644 --- a/internal/provider/privateinternetaccess/updater/hosttoserver.go +++ b/internal/provider/privateinternetaccess/updater/hosttoserver.go @@ -10,7 +10,8 @@ import ( type nameToServer map[string]models.Server func (nts nameToServer) add(name, hostname, region string, - tcp, udp, portForward bool, ip netip.Addr) (change bool) { + tcp, udp, portForward bool, ip netip.Addr, +) (change bool) { server, ok := nts[name] if !ok { change = true diff --git a/internal/provider/privateinternetaccess/updater/servers.go b/internal/provider/privateinternetaccess/updater/servers.go index 96d75187..d30ff3cc 100644 --- a/internal/provider/privateinternetaccess/updater/servers.go +++ b/internal/provider/privateinternetaccess/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { nts := make(nameToServer) noChangeCounter := 0 diff --git a/internal/provider/privatevpn/connection.go b/internal/provider/privatevpn/connection.go index 95f0ff61..ee117ec7 100644 --- a/internal/provider/privatevpn/connection.go +++ b/internal/provider/privatevpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/privatevpn/openvpnconf.go b/internal/provider/privatevpn/openvpnconf.go index 34fefbd8..8295c5c1 100644 --- a/internal/provider/privatevpn/openvpnconf.go +++ b/internal/provider/privatevpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: true, diff --git a/internal/provider/privatevpn/portforward.go b/internal/provider/privatevpn/portforward.go index 4dbc6919..2e02da28 100644 --- a/internal/provider/privatevpn/portforward.go +++ b/internal/provider/privatevpn/portforward.go @@ -14,18 +14,15 @@ import ( "github.com/qdm12/gluetun/internal/provider/utils" ) -var ( - regexPort = regexp.MustCompile(`[1-9][0-9]{0,4}`) -) +var regexPort = regexp.MustCompile(`[1-9][0-9]{0,4}`) -var ( - ErrPortForwardedNotFound = errors.New("port forwarded not found") -) +var ErrPortForwardedNotFound = errors.New("port forwarded not found") // PortForward obtains a VPN server side port forwarded from the PrivateVPN API. // It returns 0 if all ports are to forwarded on a dedicated server IP. func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) ( - ports []uint16, err error) { + ports []uint16, err error, +) { url := "https://connect.pvdatanet.com/v3/Api/port?ip[]=" + objects.InternalIP.String() request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { @@ -75,7 +72,8 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj } func (p *Provider) KeepPortForward(ctx context.Context, - _ utils.PortForwardObjects) (err error) { + _ utils.PortForwardObjects, +) (err error) { <-ctx.Done() return ctx.Err() } diff --git a/internal/provider/privatevpn/provider.go b/internal/provider/privatevpn/provider.go index 6e283562..72221727 100644 --- a/internal/provider/privatevpn/provider.go +++ b/internal/provider/privatevpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/privatevpn/updater/countries.go b/internal/provider/privatevpn/updater/countries.go index 70393056..6ea6f107 100644 --- a/internal/provider/privatevpn/updater/countries.go +++ b/internal/provider/privatevpn/updater/countries.go @@ -3,7 +3,8 @@ package updater import "strings" func codeToCountry(countryCode string, countryCodes map[string]string) ( - country string, warning string) { + country string, warning string, +) { countryCode = strings.ToLower(countryCode) country, ok := countryCodes[countryCode] if !ok { diff --git a/internal/provider/privatevpn/updater/filename.go b/internal/provider/privatevpn/updater/filename.go index 2085d3f6..50d58de9 100644 --- a/internal/provider/privatevpn/updater/filename.go +++ b/internal/provider/privatevpn/updater/filename.go @@ -7,9 +7,7 @@ import ( "strings" ) -var ( - trailingNumber = regexp.MustCompile(` [0-9]+$`) -) +var trailingNumber = regexp.MustCompile(` [0-9]+$`) var ( errBadPrefix = errors.New("bad prefix in file name") diff --git a/internal/provider/privatevpn/updater/servers.go b/internal/provider/privatevpn/updater/servers.go index 998b135c..5976def4 100644 --- a/internal/provider/privatevpn/updater/servers.go +++ b/internal/provider/privatevpn/updater/servers.go @@ -14,7 +14,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://privatevpn.com/client/PrivateVPN-TUN.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/privatevpn/updater/updater.go b/internal/provider/privatevpn/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/privatevpn/updater/updater.go +++ b/internal/provider/privatevpn/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/protonvpn/connection.go b/internal/provider/protonvpn/connection.go index c5bf13b6..b7b77d25 100644 --- a/internal/provider/protonvpn/connection.go +++ b/internal/provider/protonvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/protonvpn/openvpnconf.go b/internal/provider/protonvpn/openvpnconf.go index 07604c3c..c26da4e8 100644 --- a/internal/provider/protonvpn/openvpnconf.go +++ b/internal/provider/protonvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/protonvpn/portforward.go b/internal/provider/protonvpn/portforward.go index 0635f0bf..41f9b29e 100644 --- a/internal/provider/protonvpn/portforward.go +++ b/internal/provider/protonvpn/portforward.go @@ -11,13 +11,12 @@ import ( "github.com/qdm12/gluetun/internal/provider/utils" ) -var ( - ErrServerPortForwardNotSupported = errors.New("server does not support port forwarding") -) +var ErrServerPortForwardNotSupported = errors.New("server does not support port forwarding") // PortForward obtains a VPN server side port forwarded from ProtonVPN gateway. func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) ( - ports []uint16, err error) { + ports []uint16, err error, +) { if !objects.CanPortForward { return nil, fmt.Errorf("%w", ErrServerPortForwardNotSupported) } @@ -38,17 +37,15 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj const internalPort, externalPort = 0, 1 const lifetime = 60 * time.Second - _, _, assignedUDPExternalPort, assignedLifetime, err := - client.AddPortMapping(ctx, objects.Gateway, "udp", - internalPort, externalPort, lifetime) + _, _, assignedUDPExternalPort, assignedLifetime, err := client.AddPortMapping(ctx, objects.Gateway, "udp", + internalPort, externalPort, lifetime) if err != nil { return nil, fmt.Errorf("adding UDP port mapping: %w", err) } checkLifetime(logger, "UDP", lifetime, assignedLifetime) - _, _, assignedTCPExternalPort, assignedLifetime, err := - client.AddPortMapping(ctx, objects.Gateway, "tcp", - internalPort, externalPort, lifetime) + _, _, assignedTCPExternalPort, assignedLifetime, err := client.AddPortMapping(ctx, objects.Gateway, "tcp", + internalPort, externalPort, lifetime) if err != nil { return nil, fmt.Errorf("adding TCP port mapping: %w", err) } @@ -62,7 +59,8 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj } func checkLifetime(logger utils.Logger, protocol string, - requested, actual time.Duration) { + requested, actual time.Duration, +) { if requested != actual { logger.Warn(fmt.Sprintf("assigned %s port lifetime %s differs"+ " from requested lifetime %s", strings.ToUpper(protocol), @@ -80,7 +78,8 @@ func checkExternalPorts(logger utils.Logger, udpPort, tcpPort uint16) { var ErrExternalPortChanged = errors.New("external port changed") func (p *Provider) KeepPortForward(ctx context.Context, - objects utils.PortForwardObjects) (err error) { + objects utils.PortForwardObjects, +) (err error) { client := natpmp.New() const refreshTimeout = 45 * time.Second timer := time.NewTimer(refreshTimeout) @@ -98,9 +97,8 @@ func (p *Provider) KeepPortForward(ctx context.Context, const lifetime = 60 * time.Second for _, networkProtocol := range networkProtocols { - _, _, assignedExternalPort, assignedLiftetime, err := - client.AddPortMapping(ctx, objects.Gateway, networkProtocol, - internalPort, p.portForwarded, lifetime) + _, _, assignedExternalPort, assignedLiftetime, err := client.AddPortMapping(ctx, objects.Gateway, networkProtocol, + internalPort, p.portForwarded, lifetime) if err != nil { return fmt.Errorf("adding port mapping: %w", err) } diff --git a/internal/provider/protonvpn/provider.go b/internal/provider/protonvpn/provider.go index 902d1d16..59472bd8 100644 --- a/internal/provider/protonvpn/provider.go +++ b/internal/provider/protonvpn/provider.go @@ -17,7 +17,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - client *http.Client, updaterWarner common.Warner) *Provider { + client *http.Client, updaterWarner common.Warner, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/protonvpn/updater/api.go b/internal/provider/protonvpn/updater/api.go index 45d8cdbf..79b18fd0 100644 --- a/internal/provider/protonvpn/updater/api.go +++ b/internal/provider/protonvpn/updater/api.go @@ -9,9 +9,7 @@ import ( "net/netip" ) -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type apiData struct { LogicalServers []logicalServer `json:"LogicalServers"` @@ -36,7 +34,8 @@ type physicalServer struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { const url = "https://api.protonmail.ch/vpn/logicals" request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) diff --git a/internal/provider/protonvpn/updater/countries.go b/internal/provider/protonvpn/updater/countries.go index 70393056..6ea6f107 100644 --- a/internal/provider/protonvpn/updater/countries.go +++ b/internal/provider/protonvpn/updater/countries.go @@ -3,7 +3,8 @@ package updater import "strings" func codeToCountry(countryCode string, countryCodes map[string]string) ( - country string, warning string) { + country string, warning string, +) { countryCode = strings.ToLower(countryCode) country, ok := countryCodes[countryCode] if !ok { diff --git a/internal/provider/protonvpn/updater/iptoserver.go b/internal/provider/protonvpn/updater/iptoserver.go index 33824164..973cc5e6 100644 --- a/internal/provider/protonvpn/updater/iptoserver.go +++ b/internal/provider/protonvpn/updater/iptoserver.go @@ -17,7 +17,8 @@ type features struct { } func (its ipToServers) add(country, region, city, name, hostname, wgPubKey string, - free bool, entryIP netip.Addr, features features) { + free bool, entryIP netip.Addr, features features, +) { key := entryIP.String() servers, ok := its[key] diff --git a/internal/provider/protonvpn/updater/servers.go b/internal/provider/protonvpn/updater/servers.go index 190d256a..c7c3a0fc 100644 --- a/internal/provider/protonvpn/updater/servers.go +++ b/internal/provider/protonvpn/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { data, err := fetchAPI(ctx, u.client) if err != nil { return nil, err diff --git a/internal/provider/providers.go b/internal/provider/providers.go index e3f18381..576669f9 100644 --- a/internal/provider/providers.go +++ b/internal/provider/providers.go @@ -54,7 +54,8 @@ type Extractor interface { func NewProviders(storage Storage, timeNow func() time.Time, updaterWarner common.Warner, client *http.Client, unzipper common.Unzipper, parallelResolver common.ParallelResolver, ipFetcher common.IPFetcher, - extractor custom.Extractor) *Providers { + extractor custom.Extractor, +) *Providers { randSource := rand.NewSource(timeNow().UnixNano()) //nolint:lll diff --git a/internal/provider/purevpn/connection.go b/internal/provider/purevpn/connection.go index 1b9d337a..6f9bf61a 100644 --- a/internal/provider/purevpn/connection.go +++ b/internal/provider/purevpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(80, 53, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/purevpn/openvpnconf.go b/internal/provider/purevpn/openvpnconf.go index cd925d83..9da13985 100644 --- a/internal/provider/purevpn/openvpnconf.go +++ b/internal/provider/purevpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: true, diff --git a/internal/provider/purevpn/provider.go b/internal/provider/purevpn/provider.go index 31570f4a..f95d16c2 100644 --- a/internal/provider/purevpn/provider.go +++ b/internal/provider/purevpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, ipFetcher common.IPFetcher, unzipper common.Unzipper, - updaterWarner common.Warner, parallelResolver common.ParallelResolver) *Provider { + updaterWarner common.Warner, parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/purevpn/updater/servers.go b/internal/provider/purevpn/updater/servers.go index 76b80f36..01249650 100644 --- a/internal/provider/purevpn/updater/servers.go +++ b/internal/provider/purevpn/updater/servers.go @@ -14,7 +14,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://d11a57lttb2ffq.cloudfront.net/heartbleed/router/Recommended-CA2.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/purevpn/updater/updater.go b/internal/provider/purevpn/updater/updater.go index 65ee9cfe..2136f8ee 100644 --- a/internal/provider/purevpn/updater/updater.go +++ b/internal/provider/purevpn/updater/updater.go @@ -12,7 +12,8 @@ type Updater struct { } func New(ipFetcher common.IPFetcher, unzipper common.Unzipper, - warner common.Warner, parallelResolver common.ParallelResolver) *Updater { + warner common.Warner, parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ ipFetcher: ipFetcher, unzipper: unzipper, diff --git a/internal/provider/slickvpn/connection.go b/internal/provider/slickvpn/connection.go index 3a54131a..3c30e883 100644 --- a/internal/provider/slickvpn/connection.go +++ b/internal/provider/slickvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) } diff --git a/internal/provider/slickvpn/openvpnconf.go b/internal/provider/slickvpn/openvpnconf.go index c984b4b4..764f6ce4 100644 --- a/internal/provider/slickvpn/openvpnconf.go +++ b/internal/provider/slickvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { const pingSeconds = 10 const bufSize = 393216 providerSettings := utils.OpenVPNProviderSettings{ diff --git a/internal/provider/slickvpn/provider.go b/internal/provider/slickvpn/provider.go index f513a17f..a41d60a8 100644 --- a/internal/provider/slickvpn/provider.go +++ b/internal/provider/slickvpn/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/slickvpn/updater/servers.go b/internal/provider/slickvpn/updater/servers.go index e96e8add..6c0ce8e8 100644 --- a/internal/provider/slickvpn/updater/servers.go +++ b/internal/provider/slickvpn/updater/servers.go @@ -12,7 +12,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { hostToData, err := fetchServers(ctx, u.client) if err != nil { return nil, fmt.Errorf("fetching and parsing website: %w", err) diff --git a/internal/provider/slickvpn/updater/updater.go b/internal/provider/slickvpn/updater/updater.go index f15a2f3a..df4427cc 100644 --- a/internal/provider/slickvpn/updater/updater.go +++ b/internal/provider/slickvpn/updater/updater.go @@ -13,7 +13,8 @@ type Updater struct { } func New(client *http.Client, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, parallelResolver: parallelResolver, diff --git a/internal/provider/slickvpn/updater/website.go b/internal/provider/slickvpn/updater/website.go index b25d0734..c3271459 100644 --- a/internal/provider/slickvpn/updater/website.go +++ b/internal/provider/slickvpn/updater/website.go @@ -12,7 +12,8 @@ import ( ) func fetchServers(ctx context.Context, client *http.Client) ( - hostToData map[string]serverData, err error) { + hostToData map[string]serverData, err error, +) { const url = "https://www.slickvpn.com/locations/" rootNode, err := htmlutils.Fetch(ctx, client, url) if err != nil { @@ -133,9 +134,7 @@ func matchA(cellNode *html.Node) (match bool) { var serverNameRegex = regexp.MustCompile(`^.+\/(?P.+)\.ovpn$`) -var ( - ErrExtractHostnameFromURL = errors.New("cannot extract hostname from url") -) +var ErrExtractHostnameFromURL = errors.New("cannot extract hostname from url") func extractHostnameFromURL(url string) (hostname string, err error) { matches := serverNameRegex.FindStringSubmatch(url) diff --git a/internal/provider/surfshark/connection.go b/internal/provider/surfshark/connection.go index 60e7be6c..6c15156c 100644 --- a/internal/provider/surfshark/connection.go +++ b/internal/provider/surfshark/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(1443, 1194, 51820) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/surfshark/openvpnconf.go b/internal/provider/surfshark/openvpnconf.go index 94fa6c66..9f8cf192 100644 --- a/internal/provider/surfshark/openvpnconf.go +++ b/internal/provider/surfshark/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/surfshark/provider.go b/internal/provider/surfshark/provider.go index 47d8c9c4..ef6a6d48 100644 --- a/internal/provider/surfshark/provider.go +++ b/internal/provider/surfshark/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/surfshark/updater/api.go b/internal/provider/surfshark/updater/api.go index 82c69e5b..2b5aab09 100644 --- a/internal/provider/surfshark/updater/api.go +++ b/internal/provider/surfshark/updater/api.go @@ -11,7 +11,8 @@ import ( ) func addServersFromAPI(ctx context.Context, client *http.Client, - hts hostToServers) (err error) { + hts hostToServers, +) (err error) { data, err := fetchAPI(ctx, client) if err != nil { return err @@ -37,9 +38,7 @@ func addServersFromAPI(ctx context.Context, client *http.Client, return nil } -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type serverData struct { Host string `json:"connectionName"` @@ -50,7 +49,8 @@ type serverData struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - servers []serverData, err error) { + servers []serverData, err error, +) { const url = "https://api.surfshark.com/v4/server/clusters" for _, clustersType := range [...]string{"generic", "double", "static", "obfuscated"} { diff --git a/internal/provider/surfshark/updater/hosttoserver.go b/internal/provider/surfshark/updater/hosttoserver.go index 6c762a67..c70a3b0a 100644 --- a/internal/provider/surfshark/updater/hosttoserver.go +++ b/internal/provider/surfshark/updater/hosttoserver.go @@ -10,7 +10,8 @@ import ( type hostToServers map[string][]models.Server func (hts hostToServers) addOpenVPN(host, region, country, city, - retroLoc string, tcp, udp bool) { + retroLoc string, tcp, udp bool, +) { // Check for existing server for this host and OpenVPN. servers := hts[host] for i, existingServer := range servers { @@ -43,7 +44,8 @@ func (hts hostToServers) addOpenVPN(host, region, country, city, } func (hts hostToServers) addWireguard(host, region, country, city, retroLoc, - wgPubKey string) { + wgPubKey string, +) { // Check for existing server for this host and Wireguard. servers := hts[host] for _, existingServer := range servers { diff --git a/internal/provider/surfshark/updater/location.go b/internal/provider/surfshark/updater/location.go index 8f351d72..5ecadc40 100644 --- a/internal/provider/surfshark/updater/location.go +++ b/internal/provider/surfshark/updater/location.go @@ -7,12 +7,11 @@ import ( "github.com/qdm12/gluetun/internal/provider/surfshark/servers" ) -var ( - errHostnameNotFound = errors.New("hostname not found in hostname to location mapping") -) +var errHostnameNotFound = errors.New("hostname not found in hostname to location mapping") func getHostInformation(host string, hostnameToLocation map[string]servers.ServerLocation) ( - data servers.ServerLocation, err error) { + data servers.ServerLocation, err error, +) { locationData, ok := hostnameToLocation[host] if !ok { return locationData, fmt.Errorf("%w: %s", errHostnameNotFound, host) @@ -22,7 +21,8 @@ func getHostInformation(host string, hostnameToLocation map[string]servers.Serve } func hostToLocation(locationData []servers.ServerLocation) ( - hostToLocation map[string]servers.ServerLocation) { + hostToLocation map[string]servers.ServerLocation, +) { hostToLocation = make(map[string]servers.ServerLocation, len(locationData)) for _, data := range locationData { hostToLocation[data.Hostname] = data diff --git a/internal/provider/surfshark/updater/servers.go b/internal/provider/surfshark/updater/servers.go index 7fe7da08..1eb9d461 100644 --- a/internal/provider/surfshark/updater/servers.go +++ b/internal/provider/surfshark/updater/servers.go @@ -10,7 +10,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { hts := make(hostToServers) err = addServersFromAPI(ctx, u.client, hts) diff --git a/internal/provider/surfshark/updater/updater.go b/internal/provider/surfshark/updater/updater.go index 1d269789..e9b95c54 100644 --- a/internal/provider/surfshark/updater/updater.go +++ b/internal/provider/surfshark/updater/updater.go @@ -14,7 +14,8 @@ type Updater struct { } func New(client *http.Client, unzipper common.Unzipper, - warner common.Warner, parallelResolver common.ParallelResolver) *Updater { + warner common.Warner, parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, unzipper: unzipper, diff --git a/internal/provider/surfshark/updater/zip.go b/internal/provider/surfshark/updater/zip.go index 8d75ca71..92dabf55 100644 --- a/internal/provider/surfshark/updater/zip.go +++ b/internal/provider/surfshark/updater/zip.go @@ -11,7 +11,8 @@ import ( func addOpenVPNServersFromZip(ctx context.Context, unzipper common.Unzipper, hts hostToServers) ( - warnings []string, err error) { + warnings []string, err error, +) { const url = "https://my.surfshark.com/vpn/api/v1/server/configurations" contents, err := unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/torguard/connection.go b/internal/provider/torguard/connection.go index 8dfd077f..0a9d3aea 100644 --- a/internal/provider/torguard/connection.go +++ b/internal/provider/torguard/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(1912, 1912, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/torguard/openvpnconf.go b/internal/provider/torguard/openvpnconf.go index 52fa269b..c8c466f7 100644 --- a/internal/provider/torguard/openvpnconf.go +++ b/internal/provider/torguard/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: true, diff --git a/internal/provider/torguard/provider.go b/internal/provider/torguard/provider.go index 54f237ca..27f694b4 100644 --- a/internal/provider/torguard/provider.go +++ b/internal/provider/torguard/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/torguard/updater/hosttoserver.go b/internal/provider/torguard/updater/hosttoserver.go index 7755414a..5edecf74 100644 --- a/internal/provider/torguard/updater/hosttoserver.go +++ b/internal/provider/torguard/updater/hosttoserver.go @@ -10,7 +10,8 @@ import ( type hostToServer map[string]models.Server func (hts hostToServer) add(host, country, city string, - tcp, udp bool, ips []netip.Addr) { + tcp, udp bool, ips []netip.Addr, +) { server, ok := hts[host] if !ok { server.VPN = vpn.OpenVPN diff --git a/internal/provider/torguard/updater/servers.go b/internal/provider/torguard/updater/servers.go index cf0b54cc..6974c5b0 100644 --- a/internal/provider/torguard/updater/servers.go +++ b/internal/provider/torguard/updater/servers.go @@ -14,7 +14,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const tcpURL = "https://torguard.net/downloads/OpenVPN-TCP-Linux.zip" tcpContents, err := u.unzipper.FetchAndExtract(ctx, tcpURL) if err != nil { @@ -75,7 +76,8 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } func addServerFromOvpn(fileName string, content []byte, - hts hostToServer, tcp, udp bool, titleCaser cases.Caser) (warnings []string) { + hts hostToServer, tcp, udp bool, titleCaser cases.Caser, +) (warnings []string) { if !strings.HasSuffix(fileName, ".ovpn") { return nil // not an OpenVPN file } diff --git a/internal/provider/torguard/updater/updater.go b/internal/provider/torguard/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/torguard/updater/updater.go +++ b/internal/provider/torguard/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/utils/connection.go b/internal/provider/utils/connection.go index 70bfed60..7e10d739 100644 --- a/internal/provider/utils/connection.go +++ b/internal/provider/utils/connection.go @@ -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) diff --git a/internal/provider/utils/filtering.go b/internal/provider/utils/filtering.go index 9e387f8e..48e380d7 100644 --- a/internal/provider/utils/filtering.go +++ b/internal/provider/utils/filtering.go @@ -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 { diff --git a/internal/provider/utils/nofetcher.go b/internal/provider/utils/nofetcher.go index 390aa067..275808e9 100644 --- a/internal/provider/utils/nofetcher.go +++ b/internal/provider/utils/nofetcher.go @@ -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) } diff --git a/internal/provider/utils/openvpn.go b/internal/provider/utils/openvpn.go index 8a1f1f8a..70024abd 100644 --- a/internal/provider/utils/openvpn.go +++ b/internal/provider/utils/openvpn.go @@ -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) diff --git a/internal/provider/utils/pick.go b/internal/provider/utils/pick.go index 1ce7b1f5..74b01be9 100644 --- a/internal/provider/utils/pick.go +++ b/internal/provider/utils/pick.go @@ -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 diff --git a/internal/provider/utils/port.go b/internal/provider/utils/port.go index 4f0f9ff8..1f32ef4a 100644 --- a/internal/provider/utils/port.go +++ b/internal/provider/utils/port.go @@ -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 diff --git a/internal/provider/utils/protocol.go b/internal/provider/utils/protocol.go index cbd6eb43..143d7227 100644 --- a/internal/provider/utils/protocol.go +++ b/internal/provider/utils/protocol.go @@ -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 diff --git a/internal/provider/utils/wireguard.go b/internal/provider/utils/wireguard.go index b016ce1a..f3b205cc 100644 --- a/internal/provider/utils/wireguard.go +++ b/internal/provider/utils/wireguard.go @@ -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 diff --git a/internal/provider/vpnsecure/connection.go b/internal/provider/vpnsecure/connection.go index ea480972..faa24ad4 100644 --- a/internal/provider/vpnsecure/connection.go +++ b/internal/provider/vpnsecure/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(110, 1282, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/vpnsecure/openvpnconf.go b/internal/provider/vpnsecure/openvpnconf.go index 0fd848b7..6330b324 100644 --- a/internal/provider/vpnsecure/openvpnconf.go +++ b/internal/provider/vpnsecure/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/vpnsecure/provider.go b/internal/provider/vpnsecure/provider.go index 48c56cbb..89cfeb00 100644 --- a/internal/provider/vpnsecure/provider.go +++ b/internal/provider/vpnsecure/provider.go @@ -17,7 +17,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, client *http.Client, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/vpnsecure/updater/servers.go b/internal/provider/vpnsecure/updater/servers.go index e9235285..05445b4c 100644 --- a/internal/provider/vpnsecure/updater/servers.go +++ b/internal/provider/vpnsecure/updater/servers.go @@ -11,7 +11,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { servers, err = fetchServers(ctx, u.client, u.warner) if err != nil { return nil, fmt.Errorf("fetching servers: %w", err) diff --git a/internal/provider/vpnsecure/updater/updater.go b/internal/provider/vpnsecure/updater/updater.go index f15a2f3a..df4427cc 100644 --- a/internal/provider/vpnsecure/updater/updater.go +++ b/internal/provider/vpnsecure/updater/updater.go @@ -13,7 +13,8 @@ type Updater struct { } func New(client *http.Client, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ client: client, parallelResolver: parallelResolver, diff --git a/internal/provider/vpnsecure/updater/website.go b/internal/provider/vpnsecure/updater/website.go index 4abd9104..a783f11a 100644 --- a/internal/provider/vpnsecure/updater/website.go +++ b/internal/provider/vpnsecure/updater/website.go @@ -14,7 +14,8 @@ import ( ) func fetchServers(ctx context.Context, client *http.Client, - warner common.Warner) (servers []models.Server, err error) { + warner common.Warner, +) (servers []models.Server, err error) { const url = "https://www.vpnsecure.me/vpn-locations/" rootNode, err := htmlutils.Fetch(ctx, client, url) if err != nil { @@ -32,14 +33,13 @@ func fetchServers(ctx context.Context, client *http.Client, return servers, nil } -var ( - ErrHTMLServersDivNotFound = errors.New("HTML servers container div not found") -) +var ErrHTMLServersDivNotFound = errors.New("HTML servers container div not found") const divString = "div" func parseHTML(rootNode *html.Node) (servers []models.Server, - warnings []string, err error) { + warnings []string, err error, +) { // Find div container for all servers, searching with BFS. serversDiv := findServersDiv(rootNode) if serversDiv == nil { @@ -86,7 +86,8 @@ func parseHTML(rootNode *html.Node) (servers []models.Server, } func parseHTMLGridItem(gridItem *html.Node) ( - server models.Server, warning string) { + server models.Server, warning string, +) { gridItemDT := htmlutils.DirectChild(gridItem, matchDT) if gridItemDT == nil { return server, htmlutils.WrapWarning("grid item
not found", gridItem) @@ -221,7 +222,8 @@ func matchStatusSpan(node *html.Node) (match bool) { } func findSpanStrong(gridItemDD *html.Node, spanData string) ( - strongValue string) { + strongValue string, +) { spanFound := false for child := gridItemDD.FirstChild; child != nil; child = child.NextSibling { if !htmlutils.MatchData("div")(child) { diff --git a/internal/provider/vpnunlimited/connection.go b/internal/provider/vpnunlimited/connection.go index 4147f13b..43cd3405 100644 --- a/internal/provider/vpnunlimited/connection.go +++ b/internal/provider/vpnunlimited/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(1197, 1197, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/vpnunlimited/openvpnconf.go b/internal/provider/vpnunlimited/openvpnconf.go index 9cdda7a9..814df12e 100644 --- a/internal/provider/vpnunlimited/openvpnconf.go +++ b/internal/provider/vpnunlimited/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: false, diff --git a/internal/provider/vpnunlimited/provider.go b/internal/provider/vpnunlimited/provider.go index 35ff34d7..1f8b1522 100644 --- a/internal/provider/vpnunlimited/provider.go +++ b/internal/provider/vpnunlimited/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/vpnunlimited/updater/servers.go b/internal/provider/vpnunlimited/updater/servers.go index a4cad563..799273f9 100644 --- a/internal/provider/vpnunlimited/updater/servers.go +++ b/internal/provider/vpnunlimited/updater/servers.go @@ -10,7 +10,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { // Hardcoded data from a user provided ZIP file since it's behind a login wall hts, warnings := getHostToServer() for _, warning := range warnings { diff --git a/internal/provider/vpnunlimited/updater/updater.go b/internal/provider/vpnunlimited/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/vpnunlimited/updater/updater.go +++ b/internal/provider/vpnunlimited/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/vyprvpn/connection.go b/internal/provider/vyprvpn/connection.go index e7a0dd09..33636dbb 100644 --- a/internal/provider/vyprvpn/connection.go +++ b/internal/provider/vyprvpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/vyprvpn/openvpnconf.go b/internal/provider/vyprvpn/openvpnconf.go index 80fe21be..c19e2305 100644 --- a/internal/provider/vyprvpn/openvpnconf.go +++ b/internal/provider/vyprvpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { //nolint:mnd providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, diff --git a/internal/provider/vyprvpn/provider.go b/internal/provider/vyprvpn/provider.go index 6ad6534c..f9977f8a 100644 --- a/internal/provider/vyprvpn/provider.go +++ b/internal/provider/vyprvpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, unzipper common.Unzipper, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/vyprvpn/updater/servers.go b/internal/provider/vyprvpn/updater/servers.go index 73d694b0..92f4c6ba 100644 --- a/internal/provider/vyprvpn/updater/servers.go +++ b/internal/provider/vyprvpn/updater/servers.go @@ -12,7 +12,8 @@ import ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { const url = "https://support.vyprvpn.com/hc/article_attachments/360052617332/Vypr_OpenVPN_20200320.zip" contents, err := u.unzipper.FetchAndExtract(ctx, url) if err != nil { diff --git a/internal/provider/vyprvpn/updater/updater.go b/internal/provider/vyprvpn/updater/updater.go index 3fbee059..d61e235d 100644 --- a/internal/provider/vyprvpn/updater/updater.go +++ b/internal/provider/vyprvpn/updater/updater.go @@ -11,7 +11,8 @@ type Updater struct { } func New(unzipper common.Unzipper, warner common.Warner, - parallelResolver common.ParallelResolver) *Updater { + parallelResolver common.ParallelResolver, +) *Updater { return &Updater{ unzipper: unzipper, parallelResolver: parallelResolver, diff --git a/internal/provider/wevpn/connection.go b/internal/provider/wevpn/connection.go index 5961a600..1b7f81d7 100644 --- a/internal/provider/wevpn/connection.go +++ b/internal/provider/wevpn/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(1195, 1194, 0) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/wevpn/openvpnconf.go b/internal/provider/wevpn/openvpnconf.go index cf9231ba..603f44aa 100644 --- a/internal/provider/wevpn/openvpnconf.go +++ b/internal/provider/wevpn/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: true, diff --git a/internal/provider/wevpn/provider.go b/internal/provider/wevpn/provider.go index 0251ef46..86af0e18 100644 --- a/internal/provider/wevpn/provider.go +++ b/internal/provider/wevpn/provider.go @@ -16,7 +16,8 @@ type Provider struct { func New(storage common.Storage, randSource rand.Source, updaterWarner common.Warner, - parallelResolver common.ParallelResolver) *Provider { + parallelResolver common.ParallelResolver, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/wevpn/updater/servers.go b/internal/provider/wevpn/updater/servers.go index 142f96f9..fe32fc79 100644 --- a/internal/provider/wevpn/updater/servers.go +++ b/internal/provider/wevpn/updater/servers.go @@ -17,7 +17,8 @@ var ( ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { cities := getAvailableCities() servers = make([]models.Server, 0, len(cities)) hostnames := make([]string, len(cities)) diff --git a/internal/provider/windscribe/connection.go b/internal/provider/windscribe/connection.go index 135f0ce1..9698b728 100644 --- a/internal/provider/windscribe/connection.go +++ b/internal/provider/windscribe/connection.go @@ -7,7 +7,8 @@ import ( ) func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( - connection models.Connection, err error) { + connection models.Connection, err error, +) { defaults := utils.NewConnectionDefaults(443, 1194, 1194) //nolint:mnd return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource) diff --git a/internal/provider/windscribe/openvpnconf.go b/internal/provider/windscribe/openvpnconf.go index 598f1da3..4e411573 100644 --- a/internal/provider/windscribe/openvpnconf.go +++ b/internal/provider/windscribe/openvpnconf.go @@ -8,7 +8,8 @@ import ( ) func (p *Provider) OpenVPNConfig(connection models.Connection, - settings settings.OpenVPN, ipv6Supported bool) (lines []string) { + settings settings.OpenVPN, ipv6Supported bool, +) (lines []string) { providerSettings := utils.OpenVPNProviderSettings{ RemoteCertTLS: true, AuthUserPass: true, diff --git a/internal/provider/windscribe/provider.go b/internal/provider/windscribe/provider.go index 65850161..66b284fb 100644 --- a/internal/provider/windscribe/provider.go +++ b/internal/provider/windscribe/provider.go @@ -16,7 +16,8 @@ type Provider struct { } func New(storage common.Storage, randSource rand.Source, - client *http.Client, updaterWarner common.Warner) *Provider { + client *http.Client, updaterWarner common.Warner, +) *Provider { return &Provider{ storage: storage, randSource: randSource, diff --git a/internal/provider/windscribe/updater/api.go b/internal/provider/windscribe/updater/api.go index 0a70a46f..9ea83823 100644 --- a/internal/provider/windscribe/updater/api.go +++ b/internal/provider/windscribe/updater/api.go @@ -11,9 +11,7 @@ import ( "time" ) -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") type apiData struct { Data []regionData `json:"data"` @@ -39,7 +37,8 @@ type serverData struct { } func fetchAPI(ctx context.Context, client *http.Client) ( - data apiData, err error) { + data apiData, err error, +) { const baseURL = "https://assets.windscribe.com/serverlist/mob-v2/1/" cacheBreaker := time.Now().Unix() url := baseURL + strconv.Itoa(int(cacheBreaker)) diff --git a/internal/provider/windscribe/updater/servers.go b/internal/provider/windscribe/updater/servers.go index 6246dff1..586f9821 100644 --- a/internal/provider/windscribe/updater/servers.go +++ b/internal/provider/windscribe/updater/servers.go @@ -12,12 +12,11 @@ import ( "github.com/qdm12/gluetun/internal/provider/common" ) -var ( - ErrNoWireguardKey = errors.New("no wireguard public key found") -) +var ErrNoWireguardKey = errors.New("no wireguard public key found") func (u *Updater) FetchServers(ctx context.Context, minServers int) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { data, err := fetchAPI(ctx, u.client) if err != nil { return nil, err diff --git a/internal/publicip/api/api.go b/internal/publicip/api/api.go index 3ffb3ea6..4d415519 100644 --- a/internal/publicip/api/api.go +++ b/internal/publicip/api/api.go @@ -26,7 +26,8 @@ const ( ) func New(provider Provider, client *http.Client, token string) ( //nolint:ireturn - a API, err error) { + a API, err error, +) { switch provider { case Cloudflare: return newCloudflare(client), nil @@ -41,9 +42,7 @@ func New(provider Provider, client *http.Client, token string) ( //nolint:iretur } } -var ( - ErrProviderNotValid = errors.New("API name is not valid") -) +var ErrProviderNotValid = errors.New("API name is not valid") func ParseProvider(s string) (provider Provider, err error) { switch strings.ToLower(s) { diff --git a/internal/publicip/api/cloudflare.go b/internal/publicip/api/cloudflare.go index 867e7595..d79f3cef 100644 --- a/internal/publicip/api/cloudflare.go +++ b/internal/publicip/api/cloudflare.go @@ -26,7 +26,8 @@ func newCloudflare(client *http.Client) *cloudflare { // and returns an error if the `ip` argument is set since the Cloudflare API // can only be used to provide details about the current machine public IP. func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) ( - result models.PublicIP, err error) { + result models.PublicIP, err error, +) { url := "https://speed.cloudflare.com/meta" if ip.IsValid() { return result, fmt.Errorf("%w: cloudflare cannot provide information on the arbitrary IP address %s", diff --git a/internal/publicip/api/ifconfigco.go b/internal/publicip/api/ifconfigco.go index 245f22bc..5c278096 100644 --- a/internal/publicip/api/ifconfigco.go +++ b/internal/publicip/api/ifconfigco.go @@ -24,7 +24,8 @@ func newIfConfigCo(client *http.Client) *ifConfigCo { // using the ifconfig.co/json API. If the ip is the zero value, // the public IP address of the machine is used as the IP. func (i *ifConfigCo) FetchInfo(ctx context.Context, ip netip.Addr) ( - result models.PublicIP, err error) { + result models.PublicIP, err error, +) { url := "https://ifconfig.co/json" if ip.IsValid() { url += "?ip=" + ip.String() diff --git a/internal/publicip/api/ip2location.go b/internal/publicip/api/ip2location.go index 669e9fa7..d8fb9fce 100644 --- a/internal/publicip/api/ip2location.go +++ b/internal/publicip/api/ip2location.go @@ -27,7 +27,8 @@ func newIP2Location(client *http.Client, token string) *ip2Location { // using the api.ip2location.io API. If the ip is the zero value, // the public IP address of the machine is used as the IP. func (i *ip2Location) FetchInfo(ctx context.Context, ip netip.Addr) ( - result models.PublicIP, err error) { + result models.PublicIP, err error, +) { url := "https://api.ip2location.io/" if ip.IsValid() { url += "?ip=" + ip.String() diff --git a/internal/publicip/api/ipinfo.go b/internal/publicip/api/ipinfo.go index 15b7eefe..9212a13f 100644 --- a/internal/publicip/api/ipinfo.go +++ b/internal/publicip/api/ipinfo.go @@ -28,7 +28,8 @@ func newIPInfo(client *http.Client, token string) *ipInfo { // using the ipinfo.io API. If the ip is the zero value, the public IP address // of the machine is used as the IP. func (i *ipInfo) FetchInfo(ctx context.Context, ip netip.Addr) ( - result models.PublicIP, err error) { + result models.PublicIP, err error, +) { url := "https://ipinfo.io/" switch { case ip.Is6(): diff --git a/internal/publicip/api/multi.go b/internal/publicip/api/multi.go index be4f375a..ab46f9ee 100644 --- a/internal/publicip/api/multi.go +++ b/internal/publicip/api/multi.go @@ -14,7 +14,8 @@ import ( // an error is returned, so the results returned should be considered // incomplete in this case. func FetchMultiInfo(ctx context.Context, fetcher Fetcher, ips []netip.Addr) ( - results []models.PublicIP, err error) { + results []models.PublicIP, err error, +) { ctx, cancel := context.WithCancel(ctx) type asyncResult struct { diff --git a/internal/publicip/fs.go b/internal/publicip/fs.go index 929191f4..68ac9308 100644 --- a/internal/publicip/fs.go +++ b/internal/publicip/fs.go @@ -6,7 +6,7 @@ import ( ) func persistPublicIP(path string, content string, puid, pgid int) error { - const permission = fs.FileMode(0644) + const permission = fs.FileMode(0o644) file, err := os.OpenFile(path, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, permission) if err != nil { return err diff --git a/internal/publicip/loop.go b/internal/publicip/loop.go index c50c5ce4..0e383053 100644 --- a/internal/publicip/loop.go +++ b/internal/publicip/loop.go @@ -38,7 +38,8 @@ type Loop struct { } func NewLoop(fetcher Fetcher, logger Logger, - settings settings.PublicIP, puid, pgid int) *Loop { + settings settings.PublicIP, puid, pgid int, +) *Loop { return &Loop{ settings: settings, fetcher: fetcher, @@ -73,7 +74,8 @@ func (l *Loop) Start(_ context.Context) (_ <-chan error, err error) { func (l *Loop) run(runCtx context.Context, runDone chan<- struct{}, runTrigger <-chan context.Context, runResult chan<- error, - updateTrigger <-chan settings.PublicIP, updatedResult chan<- error) { + updateTrigger <-chan settings.PublicIP, updatedResult chan<- error, +) { defer close(runDone) for { diff --git a/internal/routing/default.go b/internal/routing/default.go index 14d8798d..12258196 100644 --- a/internal/routing/default.go +++ b/internal/routing/default.go @@ -9,9 +9,7 @@ import ( "golang.org/x/sys/unix" ) -var ( - ErrRouteDefaultNotFound = errors.New("default route not found") -) +var ErrRouteDefaultNotFound = errors.New("default route not found") type DefaultRoute struct { NetInterface string diff --git a/internal/routing/errors.go b/internal/routing/errors.go index 47b9b5f4..0750db36 100644 --- a/internal/routing/errors.go +++ b/internal/routing/errors.go @@ -4,6 +4,4 @@ import ( "errors" ) -var ( - ErrLinkDefaultNotFound = errors.New("default link not found") -) +var ErrLinkDefaultNotFound = errors.New("default link not found") diff --git a/internal/routing/ip.go b/internal/routing/ip.go index a80c04e8..72312dba 100644 --- a/internal/routing/ip.go +++ b/internal/routing/ip.go @@ -14,9 +14,7 @@ func ipIsPrivate(ip netip.Addr) bool { ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() } -var ( - errInterfaceIPNotFound = errors.New("IP address not found for interface") -) +var errInterfaceIPNotFound = errors.New("IP address not found for interface") func ipMatchesFamily(ip netip.Addr, family int) bool { return (family == netlink.FamilyV4 && ip.Is4()) || diff --git a/internal/routing/outbound.go b/internal/routing/outbound.go index cfa2e19a..828906f7 100644 --- a/internal/routing/outbound.go +++ b/internal/routing/outbound.go @@ -22,7 +22,8 @@ func (r *Routing) SetOutboundRoutes(outboundSubnets []netip.Prefix) error { } func (r *Routing) setOutboundRoutes(outboundSubnets []netip.Prefix, - defaultRoutes []DefaultRoute) (err error) { + defaultRoutes []DefaultRoute, +) (err error) { r.stateMutex.Lock() defer r.stateMutex.Unlock() @@ -47,7 +48,8 @@ func (r *Routing) setOutboundRoutes(outboundSubnets []netip.Prefix, } func (r *Routing) removeOutboundSubnets(subnets []netip.Prefix, - defaultRoutes []DefaultRoute) (warnings []string) { + defaultRoutes []DefaultRoute, +) (warnings []string) { for i, subNet := range subnets { for _, defaultRoute := range defaultRoutes { err := r.deleteRouteVia(subNet, defaultRoute.Gateway, defaultRoute.NetInterface, outboundTable) @@ -73,7 +75,8 @@ func (r *Routing) removeOutboundSubnets(subnets []netip.Prefix, } func (r *Routing) addOutboundSubnets(subnets []netip.Prefix, - defaultRoutes []DefaultRoute) (err error) { + defaultRoutes []DefaultRoute, +) (err error) { for i, subnet := range subnets { subnetIsIPv6 := subnet.Addr().Is6() subnetRouteAdded := false diff --git a/internal/routing/routes.go b/internal/routing/routes.go index 264c6394..e212d0b2 100644 --- a/internal/routing/routes.go +++ b/internal/routing/routes.go @@ -9,7 +9,8 @@ import ( ) func (r *Routing) addRouteVia(destination netip.Prefix, gateway netip.Addr, - iface string, table int) error { + iface string, table int, +) error { destinationStr := destination.String() r.logger.Info("adding route for " + destinationStr) r.logger.Debug("ip route replace " + destinationStr + @@ -37,7 +38,8 @@ func (r *Routing) addRouteVia(destination netip.Prefix, gateway netip.Addr, } func (r *Routing) deleteRouteVia(destination netip.Prefix, gateway netip.Addr, - iface string, table int) (err error) { + iface string, table int, +) (err error) { destinationStr := destination.String() r.logger.Info("deleting route for " + destinationStr) r.logger.Debug("ip route delete " + destinationStr + diff --git a/internal/routing/rules.go b/internal/routing/rules.go index 110effe6..4e3b6d03 100644 --- a/internal/routing/rules.go +++ b/internal/routing/rules.go @@ -60,7 +60,8 @@ func (r *Routing) deleteIPRule(src, dst netip.Prefix, table, priority int) error } func ruleDbgMsg(add bool, src, dst netip.Prefix, - table, priority int) (debugMessage string) { + table, priority int, +) (debugMessage string) { debugMessage = "ip rule" if add { diff --git a/internal/routing/rules_test.go b/internal/routing/rules_test.go index afd5bf8e..f139d0d6 100644 --- a/internal/routing/rules_test.go +++ b/internal/routing/rules_test.go @@ -17,7 +17,8 @@ func makeNetipPrefix(n byte) netip.Prefix { } func makeIPRule(src, dst netip.Prefix, - table, priority int) netlink.Rule { + table, priority int, +) netlink.Rule { rule := netlink.NewRule() rule.Src = src rule.Dst = dst diff --git a/internal/server/dns.go b/internal/server/dns.go index 0aa51ecd..6b758e9c 100644 --- a/internal/server/dns.go +++ b/internal/server/dns.go @@ -8,7 +8,8 @@ import ( ) func newDNSHandler(ctx context.Context, loop DNSLoop, - warner warner) http.Handler { + warner warner, +) http.Handler { return &dnsHandler{ ctx: ctx, loop: loop, diff --git a/internal/server/handlerv0.go b/internal/server/handlerv0.go index 7135bbb3..422cf558 100644 --- a/internal/server/handlerv0.go +++ b/internal/server/handlerv0.go @@ -8,7 +8,8 @@ import ( ) func newHandlerV0(ctx context.Context, logger infoWarner, - vpn VPNLooper, dns DNSLoop, updater UpdaterLooper) http.Handler { + vpn VPNLooper, dns DNSLoop, updater UpdaterLooper, +) http.Handler { return &handlerV0{ ctx: ctx, logger: logger, diff --git a/internal/server/handlerv1.go b/internal/server/handlerv1.go index 99fc97ca..c97e0cfb 100644 --- a/internal/server/handlerv1.go +++ b/internal/server/handlerv1.go @@ -10,7 +10,8 @@ import ( ) func newHandlerV1(w warner, buildInfo models.BuildInformation, - vpn, openvpn, dns, updater, publicip http.Handler) http.Handler { + vpn, openvpn, dns, updater, publicip http.Handler, +) http.Handler { return &handlerV1{ warner: w, buildInfo: buildInfo, diff --git a/internal/server/middlewares/auth/configfile_test.go b/internal/server/middlewares/auth/configfile_test.go index 77101799..02966ccc 100644 --- a/internal/server/middlewares/auth/configfile_test.go +++ b/internal/server/middlewares/auth/configfile_test.go @@ -62,7 +62,7 @@ routes = ["GET /v1/vpn/status"] tempDir := t.TempDir() filepath := tempDir + "/config.toml" - const permissions fs.FileMode = 0600 + const permissions fs.FileMode = 0o600 err := os.WriteFile(filepath, []byte(testCase.fileContent), permissions) require.NoError(t, err) diff --git a/internal/server/middlewares/auth/lookup_test.go b/internal/server/middlewares/auth/lookup_test.go index 3812daa4..e3e07525 100644 --- a/internal/server/middlewares/auth/lookup_test.go +++ b/internal/server/middlewares/auth/lookup_test.go @@ -39,7 +39,8 @@ func Test_settingsToLookupMap(t *testing.T) { }, "PUT /path": { {name: "b", checker: newNoneMethod()}, - }}, + }, + }, }, } diff --git a/internal/server/middlewares/auth/middleware.go b/internal/server/middlewares/auth/middleware.go index 0a04d7eb..8a7d6585 100644 --- a/internal/server/middlewares/auth/middleware.go +++ b/internal/server/middlewares/auth/middleware.go @@ -7,7 +7,8 @@ import ( func New(settings Settings, debugLogger DebugLogger) ( middleware func(http.Handler) http.Handler, - err error) { + err error, +) { routeToRoles, err := settingsToLookupMap(settings) if err != nil { return nil, fmt.Errorf("converting settings to lookup maps: %w", err) diff --git a/internal/server/middlewares/log/middleware.go b/internal/server/middlewares/log/middleware.go index adfa9196..52de0e08 100644 --- a/internal/server/middlewares/log/middleware.go +++ b/internal/server/middlewares/log/middleware.go @@ -8,7 +8,8 @@ import ( ) func New(logger Logger, enabled bool) ( - middleware func(http.Handler) http.Handler) { + middleware func(http.Handler) http.Handler, +) { return func(handler http.Handler) http.Handler { return &logMiddleware{ childHandler: handler, diff --git a/internal/server/openvpn.go b/internal/server/openvpn.go index d34dfd0f..3e25c5fe 100644 --- a/internal/server/openvpn.go +++ b/internal/server/openvpn.go @@ -11,7 +11,8 @@ import ( ) func newOpenvpnHandler(ctx context.Context, looper VPNLooper, - pfGetter PortForwardedGetter, w warner) http.Handler { + pfGetter PortForwardedGetter, w warner, +) http.Handler { return &openvpnHandler{ ctx: ctx, looper: looper, diff --git a/internal/server/server.go b/internal/server/server.go index 7e715dbc..3f50717b 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -14,7 +14,8 @@ func New(ctx context.Context, address string, logEnabled bool, logger Logger, pfGetter PortForwardedGetter, dnsLooper DNSLoop, updaterLooper UpdaterLooper, publicIPLooper PublicIPLoop, storage Storage, ipv6Supported bool) ( - server *httpserver.Server, err error) { + server *httpserver.Server, err error, +) { authSettings, err := auth.Read(authConfigPath) if err != nil { return nil, fmt.Errorf("reading auth settings: %w", err) diff --git a/internal/server/updater.go b/internal/server/updater.go index 2036fa1e..55dc4d83 100644 --- a/internal/server/updater.go +++ b/internal/server/updater.go @@ -20,7 +20,8 @@ type UpdaterLooper interface { func newUpdaterHandler( ctx context.Context, looper UpdaterLooper, - warner warner) http.Handler { + warner warner, +) http.Handler { return &updaterHandler{ ctx: ctx, looper: looper, diff --git a/internal/server/vpn.go b/internal/server/vpn.go index cb32c806..84f21c83 100644 --- a/internal/server/vpn.go +++ b/internal/server/vpn.go @@ -10,7 +10,8 @@ import ( ) func newVPNHandler(ctx context.Context, looper VPNLooper, - storage Storage, ipv6Supported bool, w warner) http.Handler { + storage Storage, ipv6Supported bool, w warner, +) http.Handler { return &vpnHandler{ ctx: ctx, looper: looper, diff --git a/internal/shadowsocks/state.go b/internal/shadowsocks/state.go index b7bc360d..03d5b79c 100644 --- a/internal/shadowsocks/state.go +++ b/internal/shadowsocks/state.go @@ -34,7 +34,8 @@ func (l *Loop) GetStatus() (status models.LoopStatus) { var ErrInvalidStatus = errors.New("invalid status") func (l *Loop) SetStatus(ctx context.Context, status models.LoopStatus) ( - outcome string, err error) { + outcome string, err error, +) { l.state.statusMu.Lock() defer l.state.statusMu.Unlock() existingStatus := l.state.status @@ -91,7 +92,8 @@ func (l *Loop) GetSettings() (settings settings.Shadowsocks) { } func (l *Loop) SetSettings(ctx context.Context, settings settings.Shadowsocks) ( - outcome string) { + outcome string, +) { l.state.settingsMu.Lock() settingsUnchanged := reflect.DeepEqual(settings, l.state.settings) if settingsUnchanged { diff --git a/internal/storage/filter.go b/internal/storage/filter.go index f8950953..4d74b6bc 100644 --- a/internal/storage/filter.go +++ b/internal/storage/filter.go @@ -15,7 +15,8 @@ import ( // to the given selection. The filtered servers are deep copied so they // are safe for mutation by the caller. func (s *Storage) FilterServers(provider string, selection settings.ServerSelection) ( - servers []models.Server, err error) { + servers []models.Server, err error, +) { if provider == providers.Custom { return nil, nil } @@ -47,7 +48,8 @@ func (s *Storage) FilterServers(provider string, selection settings.ServerSelect } 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 { @@ -151,7 +153,8 @@ func filterAnyByPossibilities(values, possibilities []string) (filtered bool) { } func filterByProtocol(selection settings.ServerSelection, - serverTCP, serverUDP bool) (filtered bool) { + serverTCP, serverUDP bool, +) (filtered bool) { switch selection.VPN { case vpn.Wireguard: return !serverUDP diff --git a/internal/storage/flush.go b/internal/storage/flush.go index 32d0262a..8ffcfd2f 100644 --- a/internal/storage/flush.go +++ b/internal/storage/flush.go @@ -21,7 +21,7 @@ func (s *Storage) FlushToFile(path string) error { // flushToFile flushes the merged servers data to the file // specified by path, as indented JSON. It is not thread-safe. func (s *Storage) flushToFile(path string) error { - const permission = 0644 + const permission = 0o644 dirPath := filepath.Dir(path) if err := os.MkdirAll(dirPath, permission); err != nil { return err diff --git a/internal/storage/merge.go b/internal/storage/merge.go index 476be37f..33340360 100644 --- a/internal/storage/merge.go +++ b/internal/storage/merge.go @@ -27,7 +27,8 @@ func (s *Storage) mergeServers(hardcoded, persisted models.AllServers) models.Al } func (s *Storage) mergeProviderServers(provider string, - hardcoded, persisted models.Servers) (merged models.Servers) { + hardcoded, persisted models.Servers, +) (merged models.Servers) { if persisted.Timestamp > hardcoded.Timestamp { diff := time.Unix(persisted.Timestamp, 0).Sub(time.Unix(hardcoded.Timestamp, 0)) if diff < 0 { diff --git a/internal/storage/read.go b/internal/storage/read.go index 4bb395ec..cc37a998 100644 --- a/internal/storage/read.go +++ b/internal/storage/read.go @@ -16,7 +16,8 @@ import ( // It only reads servers that have the same version as the hardcoded servers version // to avoid JSON decoding errors. func (s *Storage) readFromFile(filepath string, hardcodedVersions map[string]uint16) ( - servers models.AllServers, err error) { + servers models.AllServers, err error, +) { file, err := os.Open(filepath) if os.IsNotExist(err) { return servers, nil @@ -37,7 +38,8 @@ func (s *Storage) readFromFile(filepath string, hardcodedVersions map[string]uin } func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string]uint16) ( - servers models.AllServers, err error) { + servers models.AllServers, err error, +) { rawMessages := make(map[string]json.RawMessage) if err := json.Unmarshal(b, &rawMessages); err != nil { return servers, fmt.Errorf("decoding servers: %w", err) @@ -80,7 +82,8 @@ func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string func (s *Storage) readServers(provider string, hardcodedVersion uint16, rawMessage json.RawMessage, titleCaser cases.Caser) (servers models.Servers, - versionsMatch bool, err error) { + versionsMatch bool, err error, +) { provider = titleCaser.String(provider) var versionObject struct { diff --git a/internal/tun/create.go b/internal/tun/create.go index 809d4bad..1fe07a35 100644 --- a/internal/tun/create.go +++ b/internal/tun/create.go @@ -14,7 +14,7 @@ import ( // Create creates a TUN device at the path specified. func (t *Tun) Create(path string) (err error) { parentDir := filepath.Dir(path) - err = os.MkdirAll(parentDir, 0751) //nolint:mnd + err = os.MkdirAll(parentDir, 0o751) //nolint:mnd if err != nil { return err } diff --git a/internal/updater/html/fetch.go b/internal/updater/html/fetch.go index 86b49e5f..39603c1c 100644 --- a/internal/updater/html/fetch.go +++ b/internal/updater/html/fetch.go @@ -12,7 +12,8 @@ import ( var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code is not OK") func Fetch(ctx context.Context, client *http.Client, url string) ( - rootNode *html.Node, err error) { + rootNode *html.Node, err error, +) { request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, fmt.Errorf("creating HTTP request: %w", err) diff --git a/internal/updater/html/match.go b/internal/updater/html/match.go index 425da58e..8939d87c 100644 --- a/internal/updater/html/match.go +++ b/internal/updater/html/match.go @@ -23,7 +23,8 @@ func MatchData(data string) MatchFunc { } func DirectChild(parent *html.Node, - matchFunc MatchFunc) (child *html.Node) { + matchFunc MatchFunc, +) (child *html.Node) { for child := parent.FirstChild; child != nil; child = child.NextSibling { if matchFunc(child) { return child @@ -33,7 +34,8 @@ func DirectChild(parent *html.Node, } func DirectChildren(parent *html.Node, - matchFunc MatchFunc) (children []*html.Node) { + matchFunc MatchFunc, +) (children []*html.Node) { for child := parent.FirstChild; child != nil; child = child.NextSibling { if matchFunc(child) { children = append(children, child) diff --git a/internal/updater/loop/loop.go b/internal/updater/loop/loop.go index 91d3232e..432218b9 100644 --- a/internal/updater/loop/loop.go +++ b/internal/updater/loop/loop.go @@ -43,7 +43,8 @@ type Logger interface { } func NewLoop(settings settings.Updater, providers updater.Providers, - storage updater.Storage, client *http.Client, logger Logger) *Loop { + storage updater.Storage, client *http.Client, logger Logger, +) *Loop { return &Loop{ state: state{ status: constants.Stopped, diff --git a/internal/updater/openvpn/fetch.go b/internal/updater/openvpn/fetch.go index c863001c..61a4315a 100644 --- a/internal/updater/openvpn/fetch.go +++ b/internal/updater/openvpn/fetch.go @@ -8,7 +8,8 @@ import ( ) func FetchFile(ctx context.Context, client *http.Client, url string) ( - host string, err error) { + host string, err error, +) { b, err := fetchData(ctx, client, url) if err != nil { return "", err @@ -25,7 +26,8 @@ func FetchFile(ctx context.Context, client *http.Client, url string) ( } func fetchData(ctx context.Context, client *http.Client, url string) ( - b []byte, err error) { + b []byte, err error, +) { request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, err diff --git a/internal/updater/openvpn/multifetch.go b/internal/updater/openvpn/multifetch.go index 9b67c25c..4072ca28 100644 --- a/internal/updater/openvpn/multifetch.go +++ b/internal/updater/openvpn/multifetch.go @@ -9,7 +9,8 @@ import ( // parses them to extract each of their host. A mapping from host to // URL is returned. func FetchMultiFiles(ctx context.Context, client *http.Client, urls []string, - failEarly bool) (hostToURL map[string]string, errors []error) { + failEarly bool, +) (hostToURL map[string]string, errors []error) { ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/internal/updater/providers.go b/internal/updater/providers.go index fab84847..c3175ec6 100644 --- a/internal/updater/providers.go +++ b/internal/updater/providers.go @@ -18,7 +18,8 @@ type Provider interface { var ErrServerHasNotEnoughInformation = errors.New("server has not enough information") func (u *Updater) updateProvider(ctx context.Context, provider Provider, - minRatio float64) (err error) { + minRatio float64, +) (err error) { providerName := provider.Name() existingServersCount := u.storage.GetServersCount(providerName) minServers := int(minRatio * float64(existingServersCount)) diff --git a/internal/updater/resolver/parallel.go b/internal/updater/resolver/parallel.go index cbca1cac..3d22e1a1 100644 --- a/internal/updater/resolver/parallel.go +++ b/internal/updater/resolver/parallel.go @@ -40,7 +40,8 @@ var ( ) func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) ( - hostToIPs map[string][]netip.Addr, warnings []string, err error) { + hostToIPs map[string][]netip.Addr, warnings []string, err error, +) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -96,7 +97,8 @@ func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) ( } func (pr *Parallel) resolveAsync(ctx context.Context, host string, - settings RepeatSettings, results chan<- parallelResult, errors chan<- error) { + settings RepeatSettings, results chan<- parallelResult, errors chan<- error, +) { IPs, err := pr.repeatResolver.Resolve(ctx, host, settings) if err != nil { errors <- err diff --git a/internal/updater/resolver/repeat.go b/internal/updater/resolver/repeat.go index 85200eee..8252ab9b 100644 --- a/internal/updater/resolver/repeat.go +++ b/internal/updater/resolver/repeat.go @@ -31,7 +31,8 @@ type RepeatSettings struct { } func (r *Repeat) Resolve(ctx context.Context, host string, settings RepeatSettings) ( - ips []netip.Addr, err error) { + ips []netip.Addr, err error, +) { timedCtx, cancel := context.WithTimeout(ctx, settings.MaxDuration) defer cancel() @@ -68,7 +69,8 @@ var ( func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string, settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) ( - newNoNewCounter, newFailCounter int, err error) { + newNoNewCounter, newFailCounter int, err error, +) { IPs, err := r.lookupIPs(timedCtx, host) if err != nil { failCounter++ diff --git a/internal/updater/unzip/fetch.go b/internal/updater/unzip/fetch.go index 6dd80e8d..be9efa3a 100644 --- a/internal/updater/unzip/fetch.go +++ b/internal/updater/unzip/fetch.go @@ -8,12 +8,11 @@ import ( "net/http" ) -var ( - ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") -) +var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK") func (u *Unzipper) FetchAndExtract(ctx context.Context, url string) ( - contents map[string][]byte, err error) { + contents map[string][]byte, err error, +) { request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, err diff --git a/internal/updater/updater.go b/internal/updater/updater.go index ce8396ca..248ebd28 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -24,7 +24,8 @@ type Updater struct { } func New(httpClient *http.Client, storage Storage, - providers Providers, logger Logger) *Updater { + providers Providers, logger Logger, +) *Updater { unzipper := unzip.New(httpClient) return &Updater{ providers: providers, @@ -37,7 +38,8 @@ func New(httpClient *http.Client, storage Storage, } func (u *Updater) UpdateServers(ctx context.Context, providers []string, - minRatio float64) (err error) { + minRatio float64, +) (err error) { caser := cases.Title(language.English) for _, providerName := range providers { u.logger.Info("updating " + caser.String(providerName) + " servers...") diff --git a/internal/version/version.go b/internal/version/version.go index cc595626..010cab1f 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -15,7 +15,8 @@ import ( // GetMessage returns a message for the user describing if there is a newer version // available. It should only be called once the tunnel is established. func GetMessage(ctx context.Context, buildInfo models.BuildInformation, - client *http.Client) (message string, err error) { + client *http.Client, +) (message string, err error) { if buildInfo.Version == "latest" { // Find # of commits between current commit and latest commit commitsSince, err := getCommitsSince(ctx, client, buildInfo.Commit) diff --git a/internal/vpn/helpers.go b/internal/vpn/helpers.go index a6b292d6..53563cfc 100644 --- a/internal/vpn/helpers.go +++ b/internal/vpn/helpers.go @@ -12,7 +12,8 @@ func ptrTo[T any](value T) *T { return &value } // waitForError waits 100ms for an error in the waitError channel. func (l *Loop) waitForError(ctx context.Context, - waitError chan error) (err error) { + waitError chan error, +) (err error) { const waitDurationForError = 100 * time.Millisecond timer := time.NewTimer(waitDurationForError) select { diff --git a/internal/vpn/loop.go b/internal/vpn/loop.go index 8a90ca26..40bbf488 100644 --- a/internal/vpn/loop.go +++ b/internal/vpn/loop.go @@ -54,7 +54,8 @@ func NewLoop(vpnSettings settings.VPN, ipv6Supported bool, vpnInputPorts []uint1 portForward PortForward, starter CmdStarter, publicip PublicIPLoop, dnsLooper DNSLoop, logger log.LoggerInterface, client *http.Client, - buildInfo models.BuildInformation, versionInfo bool) *Loop { + buildInfo models.BuildInformation, versionInfo bool, +) *Loop { start := make(chan struct{}) running := make(chan models.LoopStatus) stop := make(chan struct{}) diff --git a/internal/vpn/openvpn.go b/internal/vpn/openvpn.go index 4f91de83..102640e1 100644 --- a/internal/vpn/openvpn.go +++ b/internal/vpn/openvpn.go @@ -15,7 +15,8 @@ func setupOpenVPN(ctx context.Context, fw Firewall, openvpnConf OpenVPN, providerConf provider.Provider, settings settings.VPN, ipv6Supported bool, starter CmdStarter, logger openvpn.Logger) (runner *openvpn.Runner, serverName string, - canPortForward bool, err error) { + canPortForward bool, err error, +) { connection, err := providerConf.GetConnection(settings.Provider.ServerSelection, ipv6Supported) if err != nil { return nil, "", false, fmt.Errorf("finding a valid server connection: %w", err) diff --git a/internal/vpn/portforward.go b/internal/vpn/portforward.go index b31600c8..5c3ffbb4 100644 --- a/internal/vpn/portforward.go +++ b/internal/vpn/portforward.go @@ -11,7 +11,8 @@ import ( ) func getPortForwarder(provider Provider, providers Providers, //nolint:ireturn - customPortForwarderName string) (portForwarder PortForwarder) { + customPortForwarderName string, +) (portForwarder PortForwarder) { if customPortForwarderName != "" { provider = providers.Get(customPortForwarderName) } @@ -61,7 +62,8 @@ func (n *noPortForwarder) Name() string { } func (n *noPortForwarder) PortForward(context.Context, pfutils.PortForwardObjects) ( - ports []uint16, err error) { + ports []uint16, err error, +) { return nil, fmt.Errorf("%w: for %s", ErrPortForwardingNotSupported, n.providerName) } diff --git a/internal/vpn/settings.go b/internal/vpn/settings.go index 052e6561..167b2f18 100644 --- a/internal/vpn/settings.go +++ b/internal/vpn/settings.go @@ -12,6 +12,7 @@ func (l *Loop) GetSettings() (settings settings.VPN) { func (l *Loop) SetSettings(ctx context.Context, vpn settings.VPN) ( - outcome string) { + outcome string, +) { return l.state.SetSettings(ctx, vpn) } diff --git a/internal/vpn/state/vpn.go b/internal/vpn/state/vpn.go index 4ea67fd7..cda722f8 100644 --- a/internal/vpn/state/vpn.go +++ b/internal/vpn/state/vpn.go @@ -16,7 +16,8 @@ func (s *State) GetSettings() (vpn settings.VPN) { } func (s *State) SetSettings(ctx context.Context, vpn settings.VPN) ( - outcome string) { + outcome string, +) { s.settingsMu.Lock() settingsUnchanged := reflect.DeepEqual(s.vpn, vpn) if settingsUnchanged { diff --git a/internal/vpn/status.go b/internal/vpn/status.go index 5e1d94b9..c366491c 100644 --- a/internal/vpn/status.go +++ b/internal/vpn/status.go @@ -11,6 +11,7 @@ func (l *Loop) GetStatus() (status models.LoopStatus) { } func (l *Loop) ApplyStatus(ctx context.Context, status models.LoopStatus) ( - outcome string, err error) { + outcome string, err error, +) { return l.statusManager.ApplyStatus(ctx, status) } diff --git a/internal/vpn/wireguard.go b/internal/vpn/wireguard.go index 9c1c6f58..7f5c4246 100644 --- a/internal/vpn/wireguard.go +++ b/internal/vpn/wireguard.go @@ -16,7 +16,8 @@ import ( func setupWireguard(ctx context.Context, netlinker NetLinker, fw Firewall, providerConf provider.Provider, settings settings.VPN, ipv6Supported bool, logger wireguard.Logger) ( - wireguarder *wireguard.Wireguard, serverName string, canPortForward bool, err error) { + wireguarder *wireguard.Wireguard, serverName string, canPortForward bool, err error, +) { connection, err := providerConf.GetConnection(settings.Provider.ServerSelection, ipv6Supported) if err != nil { return nil, "", false, fmt.Errorf("finding a VPN server: %w", err) diff --git a/internal/wireguard/address.go b/internal/wireguard/address.go index 196fb728..2c9c9124 100644 --- a/internal/wireguard/address.go +++ b/internal/wireguard/address.go @@ -8,7 +8,8 @@ import ( ) func (w *Wireguard) addAddresses(link netlink.Link, - addresses []netip.Prefix) (err error) { + addresses []netip.Prefix, +) (err error) { for _, ipNet := range addresses { if !*w.settings.IPv6 && ipNet.Addr().Is6() { continue diff --git a/internal/wireguard/cleanup.go b/internal/wireguard/cleanup.go index 8ca5446e..668682fe 100644 --- a/internal/wireguard/cleanup.go +++ b/internal/wireguard/cleanup.go @@ -12,7 +12,8 @@ type closer struct { type closers []closer func (c *closers) add(operation string, step step, - closeFunc func() error) { + closeFunc func() error, +) { closer := closer{ operation: operation, step: step, diff --git a/internal/wireguard/constructor.go b/internal/wireguard/constructor.go index 15c4f7c1..2b54498b 100644 --- a/internal/wireguard/constructor.go +++ b/internal/wireguard/constructor.go @@ -7,7 +7,8 @@ type Wireguard struct { } func New(settings Settings, netlink NetLinker, - logger Logger) (w *Wireguard, err error) { + logger Logger, +) (w *Wireguard, err error) { settings.SetDefaults() if err := settings.Check(); err != nil { return nil, err diff --git a/internal/wireguard/route.go b/internal/wireguard/route.go index e8e0beb5..84178d03 100644 --- a/internal/wireguard/route.go +++ b/internal/wireguard/route.go @@ -9,7 +9,8 @@ import ( ) func (w *Wireguard) addRoutes(link netlink.Link, destinations []netip.Prefix, - firewallMark uint32) (err error) { + firewallMark uint32, +) (err error) { for _, dst := range destinations { err = w.addRoute(link, dst, firewallMark) if err == nil { @@ -29,7 +30,8 @@ func (w *Wireguard) addRoutes(link netlink.Link, destinations []netip.Prefix, } func (w *Wireguard) addRoute(link netlink.Link, dst netip.Prefix, - firewallMark uint32) (err error) { + firewallMark uint32, +) (err error) { route := netlink.Route{ LinkIndex: link.Index, Dst: dst, diff --git a/internal/wireguard/rule.go b/internal/wireguard/rule.go index 79febd3c..7586b11a 100644 --- a/internal/wireguard/rule.go +++ b/internal/wireguard/rule.go @@ -7,7 +7,8 @@ import ( ) func (w *Wireguard) addRule(rulePriority int, firewallMark uint32, - family int) (cleanup func() error, err error) { + family int, +) (cleanup func() error, err error) { rule := netlink.NewRule() rule.Invert = true rule.Priority = rulePriority diff --git a/internal/wireguard/run.go b/internal/wireguard/run.go index af719d0d..e25556d4 100644 --- a/internal/wireguard/run.go +++ b/internal/wireguard/run.go @@ -140,7 +140,8 @@ type waitAndCleanupFunc func() error func setupKernelSpace(ctx context.Context, interfaceName string, netLinker NetLinker, mtu uint16, closers *closers, logger Logger) ( - link netlink.Link, waitAndCleanup waitAndCleanupFunc, err error) { + link netlink.Link, waitAndCleanup waitAndCleanupFunc, err error, +) { link = netlink.Link{ Type: "wireguard", Name: interfaceName, @@ -184,7 +185,8 @@ func setupKernelSpace(ctx context.Context, func setupUserSpace(ctx context.Context, interfaceName string, netLinker NetLinker, mtu uint16, closers *closers, logger Logger) ( - link netlink.Link, waitAndCleanup waitAndCleanupFunc, err error) { + link netlink.Link, waitAndCleanup waitAndCleanupFunc, err error, +) { tun, err := tun.CreateTUN(interfaceName, int(mtu)) if err != nil { return link, nil, fmt.Errorf("%w: %s", ErrCreateTun, err) @@ -258,7 +260,8 @@ func setupUserSpace(ctx context.Context, } func acceptAndHandle(uapi net.Listener, device *device.Device, - uapiAcceptErrorCh chan<- error) { + uapiAcceptErrorCh chan<- error, +) { for { // stopped by uapiFile.Close() conn, err := uapi.Accept() if err != nil {