diff --git a/.golangci.yml b/.golangci.yml index 09bd1317..19e55428 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,10 +10,9 @@ issues: linters: - dupl - maligned - - path: internal/unix/constants\.go + - path: internal/server/ linters: - - golint - text: don't use ALL_CAPS in Go names; use CamelCase + - dupl linters: disable-all: true enable: diff --git a/internal/constants/cyberghost.go b/internal/constants/cyberghost.go index 845f5e85..0974f621 100644 --- a/internal/constants/cyberghost.go +++ b/internal/constants/cyberghost.go @@ -41,6 +41,8 @@ func CyberghostGroupChoices() (choices []string) { } //nolint:lll +// CyberghostServers returns a slice with the server information for each +// of the Cyberghost server. func CyberghostServers() []models.CyberghostServer { return []models.CyberghostServer{ {Region: "Albania", Group: "Premium TCP Europe", IPs: []net.IP{{31, 171, 152, 99}, {31, 171, 152, 100}, {31, 171, 152, 101}, {31, 171, 152, 102}, {31, 171, 152, 105}, {31, 171, 152, 108}, {31, 171, 152, 132}, {31, 171, 152, 136}, {31, 171, 152, 139}, {31, 171, 152, 140}}}, diff --git a/internal/constants/mullvad.go b/internal/constants/mullvad.go index 9a72dbf0..6f26ab23 100644 --- a/internal/constants/mullvad.go +++ b/internal/constants/mullvad.go @@ -55,6 +55,7 @@ func MullvadISPChoices() (choices []string) { } //nolint:dupl,lll +// MullvadServers returns a slice of all the server information for Mullvad. func MullvadServers() []models.MullvadServer { return []models.MullvadServer{ {Country: "Albania", City: "Tirana", ISP: "iRegister", Owned: false, IPs: []net.IP{{31, 171, 154, 210}}, IPsV6: []net.IP{{0x2a, 0x4, 0x27, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f}}}, diff --git a/internal/constants/nordvpn.go b/internal/constants/nordvpn.go index 067c7565..c489fe44 100644 --- a/internal/constants/nordvpn.go +++ b/internal/constants/nordvpn.go @@ -22,6 +22,7 @@ func NordvpnRegionChoices() (choices []string) { } //nolint:gomnd +// NordvpnServers returns a slice of all the server information for Nordvpn. func NordvpnServers() []models.NordvpnServer { return []models.NordvpnServer{ {Region: "Albania", Number: 20, TCP: true, UDP: true, IP: net.IP{31, 171, 152, 11}}, diff --git a/internal/constants/pia.go b/internal/constants/pia.go index 422b1905..1e63014e 100644 --- a/internal/constants/pia.go +++ b/internal/constants/pia.go @@ -26,6 +26,7 @@ func PIAGeoChoices() (choices []string) { } //nolint:lll +// PIAServers returns a slice of all the server information for PIA. func PIAServers() []models.PIAServer { return []models.PIAServer{ {Region: "AU Melbourne", ServerName: "melbourne402", Protocol: "udp", PortForward: true, IP: net.IP{27, 50, 74, 220}}, diff --git a/internal/constants/purevpn.go b/internal/constants/purevpn.go index 098db781..d5adb471 100644 --- a/internal/constants/purevpn.go +++ b/internal/constants/purevpn.go @@ -42,6 +42,7 @@ func PurevpnCityChoices() (choices []string) { } //nolint:lll +// PurevpnServers returns a slice of all the server information for Purevpn. func PurevpnServers() []models.PurevpnServer { return []models.PurevpnServer{ {Country: "Australia", Region: "New South Wales", City: "Sydney", IPs: []net.IP{{192, 253, 241, 4}, {43, 245, 161, 84}}}, diff --git a/internal/constants/surfshark.go b/internal/constants/surfshark.go index 8e9a41db..e9c9e14b 100644 --- a/internal/constants/surfshark.go +++ b/internal/constants/surfshark.go @@ -22,6 +22,7 @@ func SurfsharkRegionChoices() (choices []string) { } //nolint:lll +// SurfsharkServers returns a slice of all the server information for Surfshark. func SurfsharkServers() []models.SurfsharkServer { return []models.SurfsharkServer{ {Region: "Albania", IPs: []net.IP{{31, 171, 153, 99}, {31, 171, 153, 131}, {31, 171, 154, 101}, {31, 171, 154, 149}, {31, 171, 154, 163}, {31, 171, 154, 165}}}, diff --git a/internal/models/alias.go b/internal/models/alias.go index dd6158f9..08b2c173 100644 --- a/internal/models/alias.go +++ b/internal/models/alias.go @@ -18,7 +18,7 @@ type ( VPNProvider string // NetworkProtocol contains the network protocol to be used to communicate with the VPN servers. NetworkProtocol string - // Loop status such as stopped or running. + // LoopStatus status such as stopped or running. LoopStatus string ) diff --git a/internal/routing/routing.go b/internal/routing/routing.go index 97f54843..7af3cda1 100644 --- a/internal/routing/routing.go +++ b/internal/routing/routing.go @@ -34,7 +34,7 @@ type routing struct { stateMutex sync.RWMutex } -// NewConfigurator creates a new Configurator instance. +// NewRouting creates a new routing instance. func NewRouting(logger logging.Logger) Routing { return &routing{ logger: logger.WithPrefix("routing: "), @@ -42,10 +42,10 @@ func NewRouting(logger logging.Logger) Routing { } } -func (c *routing) SetVerbose(verbose bool) { - c.verbose = verbose +func (r *routing) SetVerbose(verbose bool) { + r.verbose = verbose } -func (c *routing) SetDebug() { - c.debug = true +func (r *routing) SetDebug() { + r.debug = true } diff --git a/internal/server/dns.go b/internal/server/dns.go index af15f1fb..229597c9 100644 --- a/internal/server/dns.go +++ b/internal/server/dns.go @@ -1,4 +1,3 @@ -//nolint:dupl package server import ( diff --git a/internal/server/openvpn.go b/internal/server/openvpn.go index 2a3d7361..24af451c 100644 --- a/internal/server/openvpn.go +++ b/internal/server/openvpn.go @@ -63,7 +63,7 @@ func (h *openvpnHandler) getStatus(w http.ResponseWriter) { } } -func (h *openvpnHandler) setStatus(w http.ResponseWriter, r *http.Request) { //nolint:dupl +func (h *openvpnHandler) setStatus(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) var data statusWrapper if err := decoder.Decode(&data); err != nil { diff --git a/internal/server/updater.go b/internal/server/updater.go index 746dbcbe..a4daefdd 100644 --- a/internal/server/updater.go +++ b/internal/server/updater.go @@ -1,4 +1,3 @@ -//nolint:dupl package server import ( diff --git a/internal/unix/constants.go b/internal/unix/constants.go index 36c53608..bc139f7c 100644 --- a/internal/unix/constants.go +++ b/internal/unix/constants.go @@ -5,5 +5,5 @@ import sysunix "golang.org/x/sys/unix" // Constants used for convenience so "os" does not have to be imported const ( - S_IFCHR = sysunix.S_IFCHR + S_IFCHR = sysunix.S_IFCHR //nolint:golint ) diff --git a/internal/updater/nordvpn.go b/internal/updater/nordvpn.go index d1dc470f..29c013b7 100644 --- a/internal/updater/nordvpn.go +++ b/internal/updater/nordvpn.go @@ -3,6 +3,7 @@ package updater import ( "context" "encoding/json" + "errors" "fmt" "net" "net/http" @@ -32,6 +33,11 @@ func (u *updater) updateNordvpn(ctx context.Context) (err error) { return nil } +var ( + ErrNoIDInServerName = errors.New("no ID in server name") + ErrInvalidIDInServerName = errors.New("invalid ID in server name") +) + func findNordvpnServers(ctx context.Context, client network.Client) ( servers []models.NordvpnServer, warnings []string, err error) { const url = "https://nordvpn.com/api/server" @@ -74,12 +80,12 @@ func findNordvpnServers(ctx context.Context, client network.Client) ( } i := strings.IndexRune(jsonServer.Name, '#') if i < 0 { - return nil, nil, fmt.Errorf("No ID in server name %q", jsonServer.Name) + return nil, nil, fmt.Errorf("%w: %s", ErrNoIDInServerName, jsonServer.Name) } idString := jsonServer.Name[i+1:] idUint64, err := strconv.ParseUint(idString, 10, 16) if err != nil { - return nil, nil, fmt.Errorf("Bad ID in server name %q", jsonServer.Name) + return nil, nil, fmt.Errorf("%w: %s", ErrInvalidIDInServerName, jsonServer.Name) } server := models.NordvpnServer{ Region: jsonServer.Country, diff --git a/internal/updater/zip.go b/internal/updater/zip.go index a5778007..056353dd 100644 --- a/internal/updater/zip.go +++ b/internal/updater/zip.go @@ -4,6 +4,7 @@ import ( "archive/zip" "bytes" "context" + "errors" "fmt" "io/ioutil" "net/http" @@ -13,6 +14,10 @@ import ( "github.com/qdm12/golibs/network" ) +var ( + ErrBadStatusCode = errors.New("bad HTTP status code") +) + func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...string) ( contents map[string][]byte, err error) { contents = make(map[string][]byte) @@ -21,7 +26,7 @@ func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...st if err != nil { return nil, err } else if status != http.StatusOK { - return nil, fmt.Errorf("Getting %s results in HTTP status code %d", url, status) + return nil, fmt.Errorf("%w: fetching url %s: %d", ErrBadStatusCode, url, status) } newContents, err := zipExtractAll(zipBytes) if err != nil {