chore: use gofumpt for code formatting

This commit is contained in:
Quentin McGaw
2024-10-11 19:20:48 +00:00
parent 3daf15a612
commit 76a4bb5dc3
289 changed files with 784 additions and 548 deletions

View File

@@ -23,7 +23,7 @@ func writeIfDifferent(path, content string, puid, pgid int) (err error) {
return fmt.Errorf("obtaining file information: %w", err)
}
const perm = os.FileMode(0400)
const perm = os.FileMode(0o400)
var writeData, setChown bool
if os.IsNotExist(err) {
writeData = true

View File

@@ -6,7 +6,7 @@ import (
)
func (c *Configurator) WriteConfig(lines []string) error {
const permission = 0644
const permission = 0o644
file, err := os.OpenFile(c.configPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, permission)
if err != nil {
return err

View File

@@ -14,7 +14,8 @@ var (
// Data extracts the lines and connection from the OpenVPN configuration file.
func (e *Extractor) Data(filepath string) (lines []string,
connection models.Connection, err error) {
connection models.Connection, err error,
) {
lines, err = readCustomConfigLines(filepath)
if err != nil {
return nil, connection, fmt.Errorf("reading configuration file: %w", err)

View File

@@ -11,12 +11,11 @@ import (
"github.com/qdm12/gluetun/internal/models"
)
var (
errRemoteLineNotFound = errors.New("remote line not found")
)
var errRemoteLineNotFound = errors.New("remote line not found")
func extractDataFromLines(lines []string) (
connection models.Connection, err error) {
connection models.Connection, err error,
) {
for i, line := range lines {
hashSymbolIndex := strings.Index(line, "#")
if hashSymbolIndex >= 0 {
@@ -54,7 +53,8 @@ func extractDataFromLines(lines []string) (
}
func extractDataFromLine(line string) (
ip netip.Addr, port uint16, protocol string, err error) {
ip netip.Addr, port uint16, protocol string, err error,
) {
switch {
case strings.HasPrefix(line, "proto "):
protocol, err = extractProto(line)
@@ -108,7 +108,8 @@ var (
)
func extractRemote(line string) (ip netip.Addr, port uint16,
protocol string, err error) {
protocol string, err error,
) {
fields := strings.Fields(line)
n := len(fields)
@@ -146,9 +147,7 @@ func extractRemote(line string) (ip netip.Addr, port uint16,
return ip, port, protocol, nil
}
var (
errPostLineFieldsCount = errors.New("post line has not 2 fields as expected")
)
var errPostLineFieldsCount = errors.New("post line has not 2 fields as expected")
func extractPort(line string) (port uint16, err error) {
fields := strings.Fields(line)

View File

@@ -7,9 +7,7 @@ import (
"fmt"
)
var (
errPEMDecode = errors.New("cannot decode PEM encoded block")
)
var errPEMDecode = errors.New("cannot decode PEM encoded block")
func PEM(b []byte) (encodedData string, err error) {
pemBlock, _ := pem.Decode(b)

View File

@@ -7,7 +7,8 @@ import (
)
func readCustomConfigLines(filepath string) (
lines []string, err error) {
lines []string, err error,
) {
file, err := os.Open(filepath)
if err != nil {
return nil, err

View File

@@ -18,31 +18,38 @@ func Test_processLogLine(t *testing.T) {
"openvpn unknown": {
"message",
"message",
levelInfo},
levelInfo,
},
"openvpn note": {
"NOTE: message",
"message",
levelInfo},
levelInfo,
},
"openvpn warning": {
"WARNING: message",
"message",
levelWarn},
levelWarn,
},
"openvpn options error": {
"Options error: message",
"message",
levelError},
levelError,
},
"openvpn ignored message": {
"NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay",
"",
levelInfo},
levelInfo,
},
"openvpn success": {
"Initialization Sequence Completed",
"Initialization Sequence Completed",
levelInfo},
levelInfo,
},
"openvpn auth failed": {
"AUTH: Received control message: AUTH_FAILED",
"AUTH: Received control message: AUTH_FAILED\n\nYour credentials might be wrong 🤨\n\n",
levelError},
levelError,
},
"TLS key negotiation error": {
s: "TLS Error: TLS key negotiation failed to occur within " +
"60 seconds (check your network connectivity)",

View File

@@ -14,7 +14,8 @@ type Configurator struct {
}
func New(logger Infoer, cmder CmdRunStarter,
puid, pgid int) *Configurator {
puid, pgid int,
) *Configurator {
return &Configurator{
logger: logger,
cmder: cmder,

View File

@@ -7,15 +7,11 @@ import (
"fmt"
)
var (
// Algorithm identifiers are listed at
// https://www.ibm.com/docs/en/zos/2.3.0?topic=programming-object-identifiers
oidDESCBC = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 7} //nolint:gochecknoglobals
)
// Algorithm identifiers are listed at
// https://www.ibm.com/docs/en/zos/2.3.0?topic=programming-object-identifiers
var oidDESCBC = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 7} //nolint:gochecknoglobals
var (
ErrEncryptionAlgorithmNotPBES2 = errors.New("encryption algorithm is not PBES2")
)
var ErrEncryptionAlgorithmNotPBES2 = errors.New("encryption algorithm is not PBES2")
type encryptedPrivateKey struct {
EncryptionAlgorithm pkix.AlgorithmIdentifier
@@ -28,7 +24,8 @@ type encryptedAlgorithmParams struct {
}
func getEncryptionAlgorithmOid(der []byte) (
encryptionSchemeAlgorithm asn1.ObjectIdentifier, err error) {
encryptionSchemeAlgorithm asn1.ObjectIdentifier, err error,
) {
var encryptedPrivateKeyData encryptedPrivateKey
_, err = asn1.Unmarshal(der, &encryptedPrivateKeyData)
if err != nil {

View File

@@ -8,9 +8,7 @@ import (
pkcs8lib "github.com/youmark/pkcs8"
)
var (
ErrUnsupportedKeyType = errors.New("unsupported key type")
)
var ErrUnsupportedKeyType = errors.New("unsupported key type")
// UpgradeEncryptedKey eventually upgrades an encrypted key to a newer encryption
// if its encryption is too weak for Openvpn/Openssl.

View File

@@ -13,7 +13,8 @@ type Runner struct {
}
func NewRunner(settings settings.OpenVPN, starter CmdStarter,
logger Logger) *Runner {
logger Logger,
) *Runner {
return &Runner{
starter: starter,
logger: logger,

View File

@@ -18,7 +18,8 @@ const (
)
func start(ctx context.Context, starter CmdStarter, version string, flags []string) (
stdoutLines, stderrLines <-chan string, waitError <-chan error, err error) {
stdoutLines, stderrLines <-chan string, waitError <-chan error, err error,
) {
var bin string
switch version {
case openvpn.Openvpn25:

View File

@@ -7,7 +7,8 @@ import (
func streamLines(ctx context.Context, done chan<- struct{},
logger Logger, stdout, stderr <-chan string,
tunnelReady chan<- struct{}) {
tunnelReady chan<- struct{},
) {
defer close(done)
var line string