mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-20 11:02:59 +02:00
chore: do not use sentinel errors when unneeded
- main reason being it's a burden to always define sentinel errors at global scope, wrap them with `%w` instead of using a string directly - only use sentinel errors when it has to be checked using `errors.Is` - replace all usage of these sentinel errors in `fmt.Errorf` with direct strings that were in the sentinel error - exclude the sentinel error definition requirement from .golangci.yml - update unit tests to use ContainersError instead of ErrorIs so it stays as a "not a change detector test" without requiring a sentinel error
This commit is contained in:
@@ -11,14 +11,11 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
var regexPort = regexp.MustCompile(`[1-9][0-9]{0,4}`)
|
||||
|
||||
var ErrPortForwardedNotFound = errors.New("port forwarded not found")
|
||||
|
||||
// PortForward obtains a VPN server side port forwarded from the PrivateVPN API.
|
||||
// It returns 0 if all ports are to forwarded on a dedicated server IP.
|
||||
func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) (
|
||||
@@ -42,8 +39,7 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%w: %d %s", common.ErrHTTPStatusCodeNotOK,
|
||||
response.StatusCode, response.Status)
|
||||
return nil, fmt.Errorf("HTTP status code not OK: %d %s", response.StatusCode, response.Status)
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
@@ -62,12 +58,12 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
|
||||
return nil, fmt.Errorf("decoding JSON response: %w; data is: %s",
|
||||
err, string(bytes))
|
||||
} else if !data.Supported {
|
||||
return nil, fmt.Errorf("%w for this VPN server", common.ErrPortForwardNotSupported)
|
||||
return nil, errors.New("port forwarding not supported for this VPN server")
|
||||
}
|
||||
|
||||
portString := regexPort.FindString(data.Status)
|
||||
if portString == "" {
|
||||
return nil, fmt.Errorf("%w: in status %q", ErrPortForwardedNotFound, data.Status)
|
||||
return nil, fmt.Errorf("port forwarded not found in status %q", data.Status)
|
||||
}
|
||||
|
||||
const base, bitSize = 10, 16
|
||||
|
||||
Reference in New Issue
Block a user