mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +02:00
Fix linting errors
This commit is contained in:
+2
-3
@@ -10,10 +10,9 @@ issues:
|
|||||||
linters:
|
linters:
|
||||||
- dupl
|
- dupl
|
||||||
- maligned
|
- maligned
|
||||||
- path: internal/unix/constants\.go
|
- path: internal/server/
|
||||||
linters:
|
linters:
|
||||||
- golint
|
- dupl
|
||||||
text: don't use ALL_CAPS in Go names; use CamelCase
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ func CyberghostGroupChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
// CyberghostServers returns a slice with the server information for each
|
||||||
|
// of the Cyberghost server.
|
||||||
func CyberghostServers() []models.CyberghostServer {
|
func CyberghostServers() []models.CyberghostServer {
|
||||||
return []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}}},
|
{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}}},
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func MullvadISPChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:dupl,lll
|
//nolint:dupl,lll
|
||||||
|
// MullvadServers returns a slice of all the server information for Mullvad.
|
||||||
func MullvadServers() []models.MullvadServer {
|
func MullvadServers() []models.MullvadServer {
|
||||||
return []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}}},
|
{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}}},
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func NordvpnRegionChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gomnd
|
//nolint:gomnd
|
||||||
|
// NordvpnServers returns a slice of all the server information for Nordvpn.
|
||||||
func NordvpnServers() []models.NordvpnServer {
|
func NordvpnServers() []models.NordvpnServer {
|
||||||
return []models.NordvpnServer{
|
return []models.NordvpnServer{
|
||||||
{Region: "Albania", Number: 20, TCP: true, UDP: true, IP: net.IP{31, 171, 152, 11}},
|
{Region: "Albania", Number: 20, TCP: true, UDP: true, IP: net.IP{31, 171, 152, 11}},
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ func PIAGeoChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
// PIAServers returns a slice of all the server information for PIA.
|
||||||
func PIAServers() []models.PIAServer {
|
func PIAServers() []models.PIAServer {
|
||||||
return []models.PIAServer{
|
return []models.PIAServer{
|
||||||
{Region: "AU Melbourne", ServerName: "melbourne402", Protocol: "udp", PortForward: true, IP: net.IP{27, 50, 74, 220}},
|
{Region: "AU Melbourne", ServerName: "melbourne402", Protocol: "udp", PortForward: true, IP: net.IP{27, 50, 74, 220}},
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func PurevpnCityChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
// PurevpnServers returns a slice of all the server information for Purevpn.
|
||||||
func PurevpnServers() []models.PurevpnServer {
|
func PurevpnServers() []models.PurevpnServer {
|
||||||
return []models.PurevpnServer{
|
return []models.PurevpnServer{
|
||||||
{Country: "Australia", Region: "New South Wales", City: "Sydney", IPs: []net.IP{{192, 253, 241, 4}, {43, 245, 161, 84}}},
|
{Country: "Australia", Region: "New South Wales", City: "Sydney", IPs: []net.IP{{192, 253, 241, 4}, {43, 245, 161, 84}}},
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func SurfsharkRegionChoices() (choices []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
|
// SurfsharkServers returns a slice of all the server information for Surfshark.
|
||||||
func SurfsharkServers() []models.SurfsharkServer {
|
func SurfsharkServers() []models.SurfsharkServer {
|
||||||
return []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}}},
|
{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}}},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type (
|
|||||||
VPNProvider string
|
VPNProvider string
|
||||||
// NetworkProtocol contains the network protocol to be used to communicate with the VPN servers.
|
// NetworkProtocol contains the network protocol to be used to communicate with the VPN servers.
|
||||||
NetworkProtocol string
|
NetworkProtocol string
|
||||||
// Loop status such as stopped or running.
|
// LoopStatus status such as stopped or running.
|
||||||
LoopStatus string
|
LoopStatus string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type routing struct {
|
|||||||
stateMutex sync.RWMutex
|
stateMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigurator creates a new Configurator instance.
|
// NewRouting creates a new routing instance.
|
||||||
func NewRouting(logger logging.Logger) Routing {
|
func NewRouting(logger logging.Logger) Routing {
|
||||||
return &routing{
|
return &routing{
|
||||||
logger: logger.WithPrefix("routing: "),
|
logger: logger.WithPrefix("routing: "),
|
||||||
@@ -42,10 +42,10 @@ func NewRouting(logger logging.Logger) Routing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *routing) SetVerbose(verbose bool) {
|
func (r *routing) SetVerbose(verbose bool) {
|
||||||
c.verbose = verbose
|
r.verbose = verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *routing) SetDebug() {
|
func (r *routing) SetDebug() {
|
||||||
c.debug = true
|
r.debug = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
//nolint:dupl
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -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)
|
decoder := json.NewDecoder(r.Body)
|
||||||
var data statusWrapper
|
var data statusWrapper
|
||||||
if err := decoder.Decode(&data); err != nil {
|
if err := decoder.Decode(&data); err != nil {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
//nolint:dupl
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -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
|
S_IFCHR = sysunix.S_IFCHR //nolint:golint
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package updater
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -32,6 +33,11 @@ func (u *updater) updateNordvpn(ctx context.Context) (err error) {
|
|||||||
return nil
|
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) (
|
func findNordvpnServers(ctx context.Context, client network.Client) (
|
||||||
servers []models.NordvpnServer, warnings []string, err error) {
|
servers []models.NordvpnServer, warnings []string, err error) {
|
||||||
const url = "https://nordvpn.com/api/server"
|
const url = "https://nordvpn.com/api/server"
|
||||||
@@ -74,12 +80,12 @@ func findNordvpnServers(ctx context.Context, client network.Client) (
|
|||||||
}
|
}
|
||||||
i := strings.IndexRune(jsonServer.Name, '#')
|
i := strings.IndexRune(jsonServer.Name, '#')
|
||||||
if i < 0 {
|
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:]
|
idString := jsonServer.Name[i+1:]
|
||||||
idUint64, err := strconv.ParseUint(idString, 10, 16)
|
idUint64, err := strconv.ParseUint(idString, 10, 16)
|
||||||
if err != nil {
|
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{
|
server := models.NordvpnServer{
|
||||||
Region: jsonServer.Country,
|
Region: jsonServer.Country,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -13,6 +14,10 @@ import (
|
|||||||
"github.com/qdm12/golibs/network"
|
"github.com/qdm12/golibs/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrBadStatusCode = errors.New("bad HTTP status code")
|
||||||
|
)
|
||||||
|
|
||||||
func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...string) (
|
func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...string) (
|
||||||
contents map[string][]byte, err error) {
|
contents map[string][]byte, err error) {
|
||||||
contents = make(map[string][]byte)
|
contents = make(map[string][]byte)
|
||||||
@@ -21,7 +26,7 @@ func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if status != http.StatusOK {
|
} 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)
|
newContents, err := zipExtractAll(zipBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user