Maintenance: add revive linter

This commit is contained in:
Quentin McGaw (desktop)
2021-06-20 16:12:39 +00:00
parent d3c63680e8
commit 400affe429
16 changed files with 44 additions and 34 deletions

View File

@@ -17,6 +17,9 @@ issues:
- path: internal/configuration/ - path: internal/configuration/
linters: linters:
- dupl - dupl
- text: "exported: exported var Err*"
linters:
- revive
linters: linters:
disable-all: true disable-all: true
enable: enable:
@@ -55,6 +58,7 @@ linters:
- nolintlint - nolintlint
- prealloc - prealloc
- predeclared - predeclared
- revive
- rowserrcheck - rowserrcheck
- sqlclosecheck - sqlclosecheck
- staticcheck - staticcheck

View File

@@ -29,11 +29,7 @@ func (settings *DNS) readBlacklistBuilding(r reader) (err error) {
return err return err
} }
if err := settings.readBlacklistUnblockedHostnames(r); err != nil { return settings.readBlacklistUnblockedHostnames(r)
return err
}
return nil
} }
var ( var (

View File

@@ -69,11 +69,7 @@ func (settings *Firewall) read(r reader) (err error) {
return err return err
} }
if err := settings.readOutboundSubnets(r); err != nil { return settings.readOutboundSubnets(r)
return err
}
return nil
} }
func (settings *Firewall) readVPNInputPorts(env params.Env) (err error) { func (settings *Firewall) readVPNInputPorts(env params.Env) (err error) {

View File

@@ -1,6 +1,8 @@
package configuration package configuration
import ( import (
"errors"
"fmt"
"strings" "strings"
"github.com/qdm12/golibs/logging" "github.com/qdm12/golibs/logging"
@@ -43,6 +45,18 @@ func (settings *Settings) lines() (lines []string) {
return lines return lines
} }
var (
ErrOpenvpn = errors.New("cannot read Openvpn settings")
ErrSystem = errors.New("cannot read System settings")
ErrDNS = errors.New("cannot read DNS settings")
ErrFirewall = errors.New("cannot read firewall settings")
ErrHTTPProxy = errors.New("cannot read HTTP proxy settings")
ErrShadowsocks = errors.New("cannot read Shadowsocks settings")
ErrControlServer = errors.New("cannot read control server settings")
ErrUpdater = errors.New("cannot read Updater settings")
ErrPublicIP = errors.New("cannot read Public IP getter settings")
)
// Read obtains all configuration options for the program and returns an error as soon // Read obtains all configuration options for the program and returns an error as soon
// as an error is encountered reading them. // as an error is encountered reading them.
func (settings *Settings) Read(env params.Env, os os.OS, logger logging.Logger) (err error) { func (settings *Settings) Read(env params.Env, os os.OS, logger logging.Logger) (err error) {
@@ -54,35 +68,35 @@ func (settings *Settings) Read(env params.Env, os os.OS, logger logging.Logger)
} }
if err := settings.OpenVPN.read(r); err != nil { if err := settings.OpenVPN.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrOpenvpn, err)
} }
if err := settings.System.read(r); err != nil { if err := settings.System.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrSystem, err)
} }
if err := settings.DNS.read(r); err != nil { if err := settings.DNS.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrDNS, err)
} }
if err := settings.Firewall.read(r); err != nil { if err := settings.Firewall.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrFirewall, err)
} }
if err := settings.HTTPProxy.read(r); err != nil { if err := settings.HTTPProxy.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrHTTPProxy, err)
} }
if err := settings.ShadowSocks.read(r); err != nil { if err := settings.ShadowSocks.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrShadowsocks, err)
} }
if err := settings.ControlServer.read(r); err != nil { if err := settings.ControlServer.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrControlServer, err)
} }
if err := settings.Updater.read(r); err != nil { if err := settings.Updater.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrUpdater, err)
} }
if ip := settings.DNS.PlaintextAddress; ip != nil { if ip := settings.DNS.PlaintextAddress; ip != nil {
@@ -90,7 +104,7 @@ func (settings *Settings) Read(env params.Env, os os.OS, logger logging.Logger)
} }
if err := settings.PublicIP.read(r); err != nil { if err := settings.PublicIP.read(r); err != nil {
return err return fmt.Errorf("%w: %s", ErrPublicIP, err)
} }
return nil return nil

View File

@@ -1,5 +1,6 @@
package constants package constants
const ( const (
// HealthcheckAddress is the default listening address for the healthcheck server.
HealthcheckAddress = "127.0.0.1:9999" HealthcheckAddress = "127.0.0.1:9999"
) )

View File

@@ -1,3 +1,4 @@
//nolint:revive
package constants package constants
const ( const (

View File

@@ -21,10 +21,10 @@ const (
RootHints string = "/etc/unbound/root.hints" RootHints string = "/etc/unbound/root.hints"
// RootKey is the filepath to the root.key file used by Unbound. // RootKey is the filepath to the root.key file used by Unbound.
RootKey string = "/etc/unbound/root.key" RootKey string = "/etc/unbound/root.key"
// Client key filepath, used by Cyberghost. // ClientKey is the client key filepath.
ClientKey string = "/gluetun/client.key" ClientKey string = "/gluetun/client.key"
// Client certificate filepath, used by Cyberghost. // ClientCertificate is the client certificate filepath.
ClientCertificate string = "/gluetun/client.crt" ClientCertificate string = "/gluetun/client.crt"
// Servers information filepath. // ServersData is the server information filepath.
ServersData = "/gluetun/servers.json" ServersData = "/gluetun/servers.json"
) )

View File

@@ -48,6 +48,7 @@ func PrivadoHostnameChoices() (choices []string) {
} }
//nolint:lll //nolint:lll
// PrivadoServers returns a slice of all the Privado servers.
func PrivadoServers() []models.PrivadoServer { func PrivadoServers() []models.PrivadoServer {
return []models.PrivadoServer{ return []models.PrivadoServer{
{Country: "Argentina", Region: "Buenos Aires F.D.", City: "Buenos Aires", Hostname: "eze-001.vpn.privado.io", IP: net.IP{168, 205, 93, 211}}, {Country: "Argentina", Region: "Buenos Aires F.D.", City: "Buenos Aires", Hostname: "eze-001.vpn.privado.io", IP: net.IP{168, 205, 93, 211}},

View File

@@ -1,3 +1,4 @@
//nolint:revive
package constants package constants
import ( import (

View File

@@ -11,7 +11,7 @@ const (
Ivpn = "ivpn" Ivpn = "ivpn"
// Mullvad is a VPN provider. // Mullvad is a VPN provider.
Mullvad = "mullvad" Mullvad = "mullvad"
// NordVPN is a VPN provider. // Nordvpn is a VPN provider.
Nordvpn = "nordvpn" Nordvpn = "nordvpn"
// Privado is a VPN provider. // Privado is a VPN provider.
Privado = "privado" Privado = "privado"
@@ -21,7 +21,7 @@ const (
Privatevpn = "privatevpn" Privatevpn = "privatevpn"
// Protonvpn is a VPN provider. // Protonvpn is a VPN provider.
Protonvpn = "protonvpn" Protonvpn = "protonvpn"
// PureVPN is a VPN provider. // Purevpn is a VPN provider.
Purevpn = "purevpn" Purevpn = "purevpn"
// Surfshark is a VPN provider. // Surfshark is a VPN provider.
Surfshark = "surfshark" Surfshark = "surfshark"

View File

@@ -21,6 +21,7 @@ func VyprvpnRegionChoices() (choices []string) {
} }
//nolint:lll //nolint:lll
// VyprvpnServers returns a slice of all the VyprVPN servers.
func VyprvpnServers() []models.VyprvpnServer { func VyprvpnServers() []models.VyprvpnServer {
return []models.VyprvpnServer{ return []models.VyprvpnServer{
{Region: "Algeria", Hostname: "dz1.vyprvpn.com", TCP: false, UDP: true, IPs: []net.IP{{209, 99, 75, 20}}}, {Region: "Algeria", Hostname: "dz1.vyprvpn.com", TCP: false, UDP: true, IPs: []net.IP{{209, 99, 75, 20}}},

View File

@@ -40,6 +40,7 @@ func WindscribeHostnameChoices() (choices []string) {
} }
//nolint:lll //nolint:lll
// WindscribeServers returns a slice of all the Windscribe servers.
func WindscribeServers() []models.WindscribeServer { func WindscribeServers() []models.WindscribeServer {
return []models.WindscribeServer{ return []models.WindscribeServer{
{Region: "Albania", City: "Tirana", Hostname: "al-002.whiskergalaxy.com", IPs: []net.IP{{31, 171, 152, 178}, {31, 171, 152, 179}, {31, 171, 152, 180}}}, {Region: "Albania", City: "Tirana", Hostname: "al-002.whiskergalaxy.com", IPs: []net.IP{{31, 171, 152, 178}, {31, 171, 152, 179}, {31, 171, 152, 180}}},

View File

@@ -327,8 +327,5 @@ func writeOpenvpnConf(lines []string, openFile os.OpenFileFunc) error {
if err != nil { if err != nil {
return err return err
} }
if err := file.Close(); err != nil { return file.Close()
return err
}
return nil
} }

View File

@@ -25,6 +25,7 @@ var (
ErrBindPort = errors.New("cannot bind port") ErrBindPort = errors.New("cannot bind port")
) )
// PortForward obtains a VPN server side port forwarded from PIA.
//nolint:gocognit //nolint:gocognit
func (p *PIA) PortForward(ctx context.Context, client *http.Client, func (p *PIA) PortForward(ctx context.Context, client *http.Client,
openFile os.OpenFileFunc, logger logging.Logger, gateway net.IP, fw firewall.Configurator, openFile os.OpenFileFunc, logger logging.Logger, gateway net.IP, fw firewall.Configurator,

View File

@@ -31,11 +31,7 @@ func (r *routing) setOutboundRoutes(outboundSubnets []net.IPNet,
} }
r.removeOutboundSubnets(subnetsToRemove, defaultInterfaceName, defaultGateway) r.removeOutboundSubnets(subnetsToRemove, defaultInterfaceName, defaultGateway)
if err := r.addOutboundSubnets(subnetsToAdd, defaultInterfaceName, defaultGateway); err != nil { return r.addOutboundSubnets(subnetsToAdd, defaultInterfaceName, defaultGateway)
return err
}
return nil
} }
func (r *routing) removeOutboundSubnets(subnets []net.IPNet, func (r *routing) removeOutboundSubnets(subnets []net.IPNet,

View File

@@ -5,5 +5,5 @@ import sysunix "golang.org/x/sys/unix"
// Constants used for convenience so "os" does not have to be imported // Constants used for convenience so "os" does not have to be imported
const ( const (
S_IFCHR = sysunix.S_IFCHR //nolint:golint S_IFCHR = sysunix.S_IFCHR //nolint:revive
) )