Fix linting errors

This commit is contained in:
Quentin McGaw
2021-02-06 17:16:58 +00:00
parent 7ca9d445f1
commit 43e140e6cc
15 changed files with 31 additions and 16 deletions
+2 -3
View File
@@ -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:
+2
View File
@@ -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}}},
+1
View File
@@ -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}}},
+1
View File
@@ -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}},
+1
View File
@@ -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}},
+1
View File
@@ -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}}},
+1
View File
@@ -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}}},
+1 -1
View File
@@ -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
)
+5 -5
View File
@@ -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
}
-1
View File
@@ -1,4 +1,3 @@
//nolint:dupl
package server
import (
+1 -1
View File
@@ -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 {
-1
View File
@@ -1,4 +1,3 @@
//nolint:dupl
package server
import (
+1 -1
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
const (
S_IFCHR = sysunix.S_IFCHR
S_IFCHR = sysunix.S_IFCHR //nolint:golint
)
+8 -2
View File
@@ -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,
+6 -1
View File
@@ -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 {