chore(lint): upgrade linter to v1.56.2
This commit is contained in:
@@ -9,6 +9,7 @@ issues:
|
|||||||
- dupl
|
- dupl
|
||||||
- goerr113
|
- goerr113
|
||||||
- containedctx
|
- containedctx
|
||||||
|
- goconst
|
||||||
- path: "internal\\/server\\/.+\\.go"
|
- path: "internal\\/server\\/.+\\.go"
|
||||||
linters:
|
linters:
|
||||||
- dupl
|
- dupl
|
||||||
@@ -33,6 +34,18 @@ issues:
|
|||||||
text: "newCipherDESCBCBlock returns interface \\(github\\.com\\/youmark\\/pkcs8\\.Cipher\\)"
|
text: "newCipherDESCBCBlock returns interface \\(github\\.com\\/youmark\\/pkcs8\\.Cipher\\)"
|
||||||
linters:
|
linters:
|
||||||
- ireturn
|
- ireturn
|
||||||
|
- path: "internal\\/firewall\\/.*\\.go"
|
||||||
|
text: "string `-i ` has [1-9][0-9]* occurrences, make it a constant"
|
||||||
|
linters:
|
||||||
|
- goconst
|
||||||
|
- path: "internal\\/provider\\/ipvanish\\/updater\\/servers.go"
|
||||||
|
text: "string ` in ` has 3 occurrences, make it a constant"
|
||||||
|
linters:
|
||||||
|
- goconst
|
||||||
|
- path: "internal\\/vpn\\/portforward.go"
|
||||||
|
text: 'directive `//nolint:ireturn` is unused for linter "ireturn"'
|
||||||
|
linters:
|
||||||
|
- nolintlint
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ ARG ALPINE_VERSION=3.18
|
|||||||
ARG GO_ALPINE_VERSION=3.18
|
ARG GO_ALPINE_VERSION=3.18
|
||||||
ARG GO_VERSION=1.21
|
ARG GO_VERSION=1.21
|
||||||
ARG XCPUTRANSLATE_VERSION=v0.6.0
|
ARG XCPUTRANSLATE_VERSION=v0.6.0
|
||||||
ARG GOLANGCI_LINT_VERSION=v1.54.1
|
ARG GOLANGCI_LINT_VERSION=v1.56.2
|
||||||
ARG MOCKGEN_VERSION=v1.6.0
|
ARG MOCKGEN_VERSION=v1.6.0
|
||||||
ARG BUILDPLATFORM=linux/amd64
|
ARG BUILDPLATFORM=linux/amd64
|
||||||
|
|
||||||
|
|||||||
@@ -180,8 +180,7 @@ func (c *Config) allowOutboundSubnets(ctx context.Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !firewallUpdated {
|
if !firewallUpdated {
|
||||||
c.logger.Info(fmt.Sprintf("ignoring subnet %s which has "+
|
c.logIgnoredSubnetFamily(subnet)
|
||||||
"no default route matching its family", subnet))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
package firewall
|
package firewall
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/netip"
|
||||||
|
)
|
||||||
|
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
Debug(s string)
|
Debug(s string)
|
||||||
Info(s string)
|
Info(s string)
|
||||||
Error(s string)
|
Error(s string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) logIgnoredSubnetFamily(subnet netip.Prefix) {
|
||||||
|
c.logger.Info(fmt.Sprintf("ignoring subnet %s which has "+
|
||||||
|
"no default route matching its family", subnet))
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ func (c *Config) removeOutboundSubnets(ctx context.Context, subnets []netip.Pref
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !firewallUpdated {
|
if !firewallUpdated {
|
||||||
c.logger.Info(fmt.Sprintf("ignoring subnet %s which has "+
|
c.logIgnoredSubnetFamily(subNet)
|
||||||
"no default route matching its family", subNet))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.outboundSubnets = subnet.RemoveSubnetFromSubnets(c.outboundSubnets, subNet)
|
c.outboundSubnets = subnet.RemoveSubnetFromSubnets(c.outboundSubnets, subNet)
|
||||||
@@ -86,8 +85,7 @@ func (c *Config) addOutboundSubnets(ctx context.Context, subnets []netip.Prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !firewallUpdated {
|
if !firewallUpdated {
|
||||||
c.logger.Info(fmt.Sprintf("ignoring subnet %s which has "+
|
c.logIgnoredSubnetFamily(subnet)
|
||||||
"no default route matching its family", subnet))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.outboundSubnets = append(c.outboundSubnets, subnet)
|
c.outboundSubnets = append(c.outboundSubnets, subnet)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ func Test_testIptablesPath(t *testing.T) {
|
|||||||
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
||||||
Return("\nChain INPUT (policy "+inputPolicy+")\nxx\n", nil)
|
Return("\nChain INPUT (policy "+inputPolicy+")\nAA\n", nil)
|
||||||
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
||||||
Return("Permission denied (you must be root)", errDummy)
|
Return("Permission denied (you must be root)", errDummy)
|
||||||
return runner
|
return runner
|
||||||
@@ -229,7 +229,7 @@ func Test_testIptablesPath(t *testing.T) {
|
|||||||
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
||||||
Return("\nChain INPUT (policy "+inputPolicy+")\nxx\n", nil)
|
Return("\nChain INPUT (policy "+inputPolicy+")\nBB\n", nil)
|
||||||
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
||||||
Return("some output", errDummy)
|
Return("some output", errDummy)
|
||||||
return runner
|
return runner
|
||||||
@@ -242,7 +242,7 @@ func Test_testIptablesPath(t *testing.T) {
|
|||||||
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newAppendTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
runner.EXPECT().Run(newDeleteTestRuleMatcher(path)).Return("", nil)
|
||||||
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
runner.EXPECT().Run(newListInputRulesMatcher(path)).
|
||||||
Return("\nChain INPUT (policy "+inputPolicy+")\nxx\n", nil)
|
Return("\nChain INPUT (policy "+inputPolicy+")\nCC\n", nil)
|
||||||
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
runner.EXPECT().Run(newSetPolicyMatcher(path, inputPolicy)).
|
||||||
Return("some output", nil)
|
Return("some output", nil)
|
||||||
return runner
|
return runner
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AllServers struct { //nolint:musttag
|
type AllServers struct {
|
||||||
Version uint16 // used for migration of the top level scheme
|
Version uint16 // used for migration of the top level scheme
|
||||||
ProviderToServers map[string]Servers
|
ProviderToServers map[string]Servers
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,19 +41,19 @@ func Test_Updater_GetServers(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
"unzipper error": {
|
"unzipper error": {
|
||||||
warnerBuilder: func(ctrl *gomock.Controller) common.Warner { return nil },
|
warnerBuilder: func(_ *gomock.Controller) common.Warner { return nil },
|
||||||
unzipErr: errors.New("dummy"),
|
unzipErr: errors.New("dummy"),
|
||||||
err: errors.New("dummy"),
|
err: errors.New("dummy"),
|
||||||
},
|
},
|
||||||
"not enough unzip contents": {
|
"not enough unzip contents": {
|
||||||
minServers: 1,
|
minServers: 1,
|
||||||
warnerBuilder: func(ctrl *gomock.Controller) common.Warner { return nil },
|
warnerBuilder: func(_ *gomock.Controller) common.Warner { return nil },
|
||||||
unzipContents: map[string][]byte{},
|
unzipContents: map[string][]byte{},
|
||||||
err: errors.New("not enough servers found: 0 and expected at least 1"),
|
err: errors.New("not enough servers found: 0 and expected at least 1"),
|
||||||
},
|
},
|
||||||
"no openvpn file": {
|
"no openvpn file": {
|
||||||
minServers: 1,
|
minServers: 1,
|
||||||
warnerBuilder: func(ctrl *gomock.Controller) common.Warner { return nil },
|
warnerBuilder: func(_ *gomock.Controller) common.Warner { return nil },
|
||||||
unzipContents: map[string][]byte{"somefile.txt": {}},
|
unzipContents: map[string][]byte{"somefile.txt": {}},
|
||||||
err: errors.New("not enough servers found: 0 and expected at least 1"),
|
err: errors.New("not enough servers found: 0 and expected at least 1"),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func Test_Updater_GetServers(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
"http response error": {
|
"http response error": {
|
||||||
warnerBuilder: func(ctrl *gomock.Controller) common.Warner { return nil },
|
warnerBuilder: func(_ *gomock.Controller) common.Warner { return nil },
|
||||||
responseStatus: http.StatusNoContent,
|
responseStatus: http.StatusNoContent,
|
||||||
err: errors.New("fetching API: HTTP status code not OK: 204 No Content"),
|
err: errors.New("fetching API: HTTP status code not OK: 204 No Content"),
|
||||||
},
|
},
|
||||||
@@ -77,7 +77,7 @@ func Test_Updater_GetServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"not enough servers": {
|
"not enough servers": {
|
||||||
minServers: 2,
|
minServers: 2,
|
||||||
warnerBuilder: func(ctrl *gomock.Controller) common.Warner { return nil },
|
warnerBuilder: func(_ *gomock.Controller) common.Warner { return nil },
|
||||||
responseBody: `{"servers":[
|
responseBody: `{"servers":[
|
||||||
{"hostnames":{"openvpn":"hosta"}}
|
{"hostnames":{"openvpn":"hosta"}}
|
||||||
]}`,
|
]}`,
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ func (h *dnsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
errRouteNotSupported(w, r.RequestURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
internal/server/helpers.go
Normal file
13
internal/server/helpers.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func errMethodNotSupported(w http.ResponseWriter, method string) {
|
||||||
|
http.Error(w, "method "+method+" not supported", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errRouteNotSupported(w http.ResponseWriter, route string) {
|
||||||
|
http.Error(w, "route "+route+" not supported", http.StatusBadRequest)
|
||||||
|
}
|
||||||
@@ -34,24 +34,24 @@ func (h *openvpnHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
case "/settings":
|
case "/settings":
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
h.getSettings(w)
|
h.getSettings(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
case "/portforwarded":
|
case "/portforwarded":
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
h.getPortForwarded(w)
|
h.getPortForwarded(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
errRouteNotSupported(w, r.RequestURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ func (h *publicIPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
h.getPublicIP(w)
|
h.getPublicIP(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
errRouteNotSupported(w, r.RequestURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ func (h *updaterHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
errRouteNotSupported(w, r.RequestURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (h *vpnHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
case "/settings":
|
case "/settings":
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
@@ -47,10 +47,10 @@ func (h *vpnHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
h.patchSettings(w, r)
|
h.patchSettings(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
errMethodNotSupported(w, r.Method)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
errRouteNotSupported(w, r.RequestURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
internal/storage/helpers.go
Normal file
8
internal/storage/helpers.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func panicOnProviderMissingHardcoded(provider string) {
|
||||||
|
panic(fmt.Sprintf("provider %s not found in hardcoded servers map; "+
|
||||||
|
"did you add the provider key in the embedded servers.json?", provider))
|
||||||
|
}
|
||||||
@@ -51,8 +51,7 @@ func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string
|
|||||||
for _, provider := range allProviders {
|
for _, provider := range allProviders {
|
||||||
hardcodedVersion, ok := hardcodedVersions[provider]
|
hardcodedVersion, ok := hardcodedVersions[provider]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("provider %s not found in hardcoded servers map; "+
|
panicOnProviderMissingHardcoded(provider)
|
||||||
"did you add the provider key in the embedded servers.json?", provider))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rawMessage, ok := rawMessages[provider]
|
rawMessage, ok := rawMessages[provider]
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ func (s *Storage) ServersAreEqual(provider string, servers []models.Server) (equ
|
|||||||
func (s *Storage) getMergedServersObject(provider string) (serversObject models.Servers) {
|
func (s *Storage) getMergedServersObject(provider string) (serversObject models.Servers) {
|
||||||
serversObject, ok := s.mergedServers.ProviderToServers[provider]
|
serversObject, ok := s.mergedServers.ProviderToServers[provider]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("provider %s not found in hardcoded servers map; "+
|
panicOnProviderMissingHardcoded(provider)
|
||||||
"did you add the provider key in the embedded servers.json?", provider))
|
|
||||||
}
|
}
|
||||||
return serversObject
|
return serversObject
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func newResolver(resolverAddress string) *net.Resolver {
|
|||||||
resolverAddress = net.JoinHostPort(resolverAddress, "53")
|
resolverAddress = net.JoinHostPort(resolverAddress, "53")
|
||||||
return &net.Resolver{
|
return &net.Resolver{
|
||||||
PreferGo: true,
|
PreferGo: true,
|
||||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
Dial: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||||
return d.DialContext(ctx, "udp", resolverAddress)
|
return d.DialContext(ctx, "udp", resolverAddress)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func Test_Wireguard_addAddresses(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"ignore IPv6": {
|
"ignore IPv6": {
|
||||||
addrs: []netip.Prefix{ipNetTwo},
|
addrs: []netip.Prefix{ipNetTwo},
|
||||||
wgBuilder: func(ctrl *gomock.Controller, link netlink.Link) *Wireguard {
|
wgBuilder: func(_ *gomock.Controller, _ netlink.Link) *Wireguard {
|
||||||
return &Wireguard{
|
return &Wireguard{
|
||||||
settings: Settings{
|
settings: Settings{
|
||||||
IPv6: ptrTo(false),
|
IPv6: ptrTo(false),
|
||||||
|
|||||||
Reference in New Issue
Block a user