Skip to content

Commit

Permalink
refactor(gofumpt): run gofumpt over the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusted authored and foxcpp committed Aug 10, 2021
1 parent 32b7526 commit b8d8ca6
Show file tree
Hide file tree
Showing 30 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func LogOutputOption(args []string) (log.Output, error) {
// keep the absolute path for reinitialization.
args[i] = absPath

w, err := os.OpenFile(absPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
w, err := os.OpenFile(absPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o666)
if err != nil {
return nil, fmt.Errorf("failed to create log file: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion framework/address/norm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
)

func addrFuncTest(t *testing.T, f func(string) (string, error)) func(in string, wantOut string, fail bool) {
func addrFuncTest(t *testing.T, f func(string) (string, error)) func(in, wantOut string, fail bool) {
return func(in, wantOut string, fail bool) {
t.Helper()

Expand Down
4 changes: 1 addition & 3 deletions framework/address/rfc6531.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"golang.org/x/text/unicode/norm"
)

var (
ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")
)
var ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")

// ToASCII converts the domain part of the email address to the A-label form and
// fails with ErrUnicodeMailbox if the local-part contains non-ASCII characters.
Expand Down
2 changes: 1 addition & 1 deletion framework/cfgparser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func validateNodeName(s string) error {
return errors.New("directive name cannot start with a digit")
}

var allowedPunct = map[rune]bool{'.': true, '-': true, '_': true}
allowedPunct := map[rune]bool{'.': true, '-': true, '_': true}

for _, ch := range s {
if !unicode.IsLetter(ch) &&
Expand Down
2 changes: 1 addition & 1 deletion framework/config/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (m *Map) AllowUnknown() {
// slice. At least one argument should be present.
//
// See Map.Custom for description of inheritGlobal and required.
func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed []string, defaultVal []string, store *[]string) {
func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed, defaultVal []string, store *[]string) {
m.Custom(name, inheritGlobal, required, func() (interface{}, error) {
return defaultVal, nil
}, func(_ *Map, node Node) (interface{}, error) {
Expand Down
4 changes: 2 additions & 2 deletions framework/config/module/modconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
)

// createInlineModule is a helper function for config matchers that can create inline modules.
func createInlineModule(preferredNamespace string, modName string, args []string) (module.Module, error) {
func createInlineModule(preferredNamespace, modName string, args []string) (module.Module, error) {
var newMod module.FuncNewModule
var originalModName = modName
originalModName := modName

// First try to extend the name with preferred namespace unless the name
// already contains it.
Expand Down
2 changes: 1 addition & 1 deletion framework/dns/dnssec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestExtResolver_AuthLookupIPAddr(t *testing.T) {
// Silence log messages about disregarded I/O errors.
log.DefaultLogger.Out = nil

test := func(aAct, aaaaAct TestSrvAction, aAD, aaaaAD bool, ad bool, addrs []net.IP, err bool) {
test := func(aAct, aaaaAct TestSrvAction, aAD, aaaaAD, ad bool, addrs []net.IP, err bool) {
t.Helper()
t.Run(fmt.Sprintln(aAct, aaaaAct, aAD, aaaaAD), func(t *testing.T) {
t.Helper()
Expand Down
4 changes: 1 addition & 3 deletions framework/dns/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"time"
)

var (
overrideServ string
)
var overrideServ string

// override globally overrides the used DNS server address with one provided.
// This function is meant only for testing. It should be called before any modules are
Expand Down
14 changes: 7 additions & 7 deletions framework/logparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ func TestParse(t *testing.T) {
}

test("2006-01-02T15:04:05.000Z module: hello\t", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Module: "module",
Message: "hello",
Context: map[string]interface{}{},
}, "")
test("2006-01-02T15:04:05.000Z module: hello: whatever\t", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Module: "module",
Message: "hello: whatever",
Context: map[string]interface{}{},
}, "")
test("2006-01-02T15:04:05.000Z module: hello: whatever\t{\"a\":1}", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Module: "module",
Message: "hello: whatever",
Context: map[string]interface{}{
"a": float64(1),
},
}, "")
test("2006-01-02T15:04:05.000Z module: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Module: "module",
Message: "hello: whatever",
Context: map[string]interface{}{
Expand All @@ -79,7 +79,7 @@ func TestParse(t *testing.T) {
},
}, "")
test("2006-01-02T15:04:05.000Z [debug] module: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Debug: true,
Module: "module",
Message: "hello: whatever",
Expand All @@ -89,7 +89,7 @@ func TestParse(t *testing.T) {
},
}, "")
test("2006-01-02T15:04:05.000Z [debug] oink oink: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Debug: true,
Message: "oink oink: hello: whatever",
Context: map[string]interface{}{
Expand All @@ -98,7 +98,7 @@ func TestParse(t *testing.T) {
},
}, "")
test("2006-01-02T15:04:05.000Z [debug] whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
Debug: true,
Message: "whatever",
Context: map[string]interface{}{
Expand Down
10 changes: 4 additions & 6 deletions framework/module/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ package module

import "errors"

var (
// ErrUnknownCredentials should be returned by auth. provider if supplied
// credentials are valid for it but are not recognized (e.g. not found in
// used DB).
ErrUnknownCredentials = errors.New("unknown credentials")
)
// ErrUnknownCredentials should be returned by auth. provider if supplied
// credentials are valid for it but are not recognized (e.g. not found in
// used DB).
var ErrUnknownCredentials = errors.New("unknown credentials")

// PlainAuth is the interface implemented by modules providing authentication using
// username:password pairs.
Expand Down
1 change: 1 addition & 0 deletions internal/auth/pam/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package pam
#include "pam.h"
*/
import "C"

import (
"errors"
"fmt"
Expand Down
6 changes: 4 additions & 2 deletions internal/auth/shadow/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import (
"strings"
)

var ErrNoSuchUser = errors.New("shadow: user entry is not present in database")
var ErrWrongPassword = errors.New("shadow: wrong password")
var (
ErrNoSuchUser = errors.New("shadow: user entry is not present in database")
ErrWrongPassword = errors.New("shadow: wrong password")
)

// Read reads system shadow passwords database and returns all entires in it.
func Read() ([]Entry, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/check/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestRequireMatchingRDNS(t *testing.T) {
test := func(rdns string, srcHost string, fail bool) {
test := func(rdns, srcHost string, fail bool) {
rdnsFut := future.New()
var ptr []string
if rdns != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/dmarc/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Verifier struct {
// TODO(GH #206): DMARC reporting
// FailureReportFunc is the callback that is called when a failure report
// is generated. If it is nil - failure reports generation is disabled.
//FailureReportFunc func(textproto.Header, io.Reader)
// FailureReportFunc func(textproto.Header, io.Reader)
}

func NewVerifier(r Resolver) *Verifier {
Expand Down
6 changes: 3 additions & 3 deletions internal/endpoint/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func bufferModeDirective(_ *config.Map, node config.Node) (interface{}, error) {
return buffer.BufferInMemory, nil
case "fs":
path := filepath.Join(config.StateDirectory, "buffer")
if err := os.MkdirAll(path, 0700); err != nil {
if err := os.MkdirAll(path, 0o700); err != nil {
return nil, err
}
switch len(node.Args) {
Expand All @@ -206,7 +206,7 @@ func bufferModeDirective(_ *config.Map, node config.Node) (interface{}, error) {
}
case "auto":
path := filepath.Join(config.StateDirectory, "buffer")
if err := os.MkdirAll(path, 0700); err != nil {
if err := os.MkdirAll(path, 0o700); err != nil {
return nil, err
}

Expand Down Expand Up @@ -251,7 +251,7 @@ func (endp *Endpoint) setConfig(cfg *config.Map) error {
cfg.Int("max_received", false, false, 50, &endp.maxReceived)
cfg.Custom("buffer", false, false, func() (interface{}, error) {
path := filepath.Join(config.StateDirectory, "buffer")
if err := os.MkdirAll(path, 0700); err != nil {
if err := os.MkdirAll(path, 0o700); err != nil {
return nil, err
}
return autoBufferMode(1*1024*1024 /* 1 MiB */, path), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/endpoint/smtp/submission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
}

func TestSubmissionPrepare(t *testing.T) {
test := func(hdrMap map[string][]string, expectedMap map[string][]string) {
test := func(hdrMap, expectedMap map[string][]string) {
t.Helper()

hdr := textproto.Header{}
Expand Down
4 changes: 1 addition & 3 deletions internal/limits/limiters/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"time"
)

var (
ErrClosed = errors.New("limiters: Rate bucket is closed")
)
var ErrClosed = errors.New("limiters: Rate bucket is closed")

// Rate structure implements a basic rate-limiter for requests using the token
// bucket approach.
Expand Down
4 changes: 2 additions & 2 deletions internal/modify/dkim/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m *Modifier) generateAndWrite(keyPath, newKeyAlgo string) (crypto.Signer,

// 0777 because we have public keys in here too and they don't
// need protection. Individual private key files have 0600 perms.
if err := os.MkdirAll(filepath.Dir(keyPath), 0777); err != nil {
if err := os.MkdirAll(filepath.Dir(keyPath), 0o777); err != nil {
return nil, wrapErr(err)
}

Expand All @@ -136,7 +136,7 @@ func (m *Modifier) generateAndWrite(keyPath, newKeyAlgo string) (crypto.Signer,
return nil, wrapErr(err)
}

f, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
f, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)
if err != nil {
return nil, wrapErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/modify/dkim/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestKeyLoad_existing_pkcs8(t *testing.T) {
}
defer os.RemoveAll(dir)

if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyEd25519), 0600); err != nil {
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyEd25519), 0o600); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func TestKeyLoad_existing_pkcs1(t *testing.T) {
}
defer os.RemoveAll(dir)

if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyRSA), 0600); err != nil {
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyRSA), 0o600); err != nil {
t.Fatal(err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/msgpipeline/msgpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (dd *msgpipelineDelivery) initRunGlobalModifiers(ctx context.Context, msgMe
}

func (dd *msgpipelineDelivery) srcBlockForAddr(ctx context.Context, mailFrom string) (sourceBlock, error) {
var cleanFrom = mailFrom
cleanFrom := mailFrom
if mailFrom != "" {
var err error
cleanFrom, err = address.ForLookup(mailFrom)
Expand Down
6 changes: 4 additions & 2 deletions internal/msgpipeline/msgpipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ func TestMsgPipeline_PerSourceAddrAndDomainSplit(t *testing.T) {
targets: []module.DeliveryTarget{&target1},
},
},
"example.com": {perRcpt: map[string]*rcptBlock{},
"example.com": {
perRcpt: map[string]*rcptBlock{},
defaultRcpt: &rcptBlock{
targets: []module.DeliveryTarget{&target2},
},
Expand Down Expand Up @@ -365,7 +366,8 @@ func TestMsgPipeline_PerSourceReject(t *testing.T) {
targets: []module.DeliveryTarget{&target},
},
},
"example.com": {perRcpt: map[string]*rcptBlock{},
"example.com": {
perRcpt: map[string]*rcptBlock{},
rejectErr: errors.New("go away"),
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/target/remote/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func isVerifyError(err error) bool {
// Return values:
// - tlsLevel TLS security level that was estabilished.
// - tlsErr Error that prevented TLS from working if tlsLevel != TLSAuthenticated
func (rd *remoteDelivery) connect(ctx context.Context, conn mxConn, host string, tlsCfg *tls.Config) (tlsLevel module.TLSLevel, tlsErr error, err error) {
func (rd *remoteDelivery) connect(ctx context.Context, conn mxConn, host string, tlsCfg *tls.Config) (tlsLevel module.TLSLevel, tlsErr, err error) {
tlsLevel = module.TLSAuthenticated
if rd.rt.tlsConfig != nil {
tlsCfg = rd.rt.tlsConfig.Clone()
Expand Down
1 change: 0 additions & 1 deletion internal/target/smtp/smtp_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ func (d *delivery) connect(ctx context.Context) error {

func (d *delivery) AddRcpt(ctx context.Context, rcptTo string) error {
err := d.conn.Rcpt(ctx, rcptTo)

if err != nil {
return d.u.moduleError(err)
}
Expand Down
10 changes: 4 additions & 6 deletions internal/testutils/smtp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ func (s *session) LMTPData(r io.Reader, status smtp.StatusCollector) error {

type SMTPServerConfigureFunc func(*smtp.Server)

var (
AuthDisabled = func(s *smtp.Server) {
s.AuthDisabled = true
}
)
var AuthDisabled = func(s *smtp.Server) {
s.AuthDisabled = true
}

func SMTPServer(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*SMTPBackend, *smtp.Server) {
t.Helper()
Expand Down Expand Up @@ -383,7 +381,7 @@ func CheckSMTPConnLeak(t *testing.T, srv *smtp.Server) {
// wait a bit for handleQuit in go-smtp to do its work.
for i := 0; i < 10; i++ {
found := false
srv.ForEachConn(func(c *smtp.Conn) {
srv.ForEachConn(func(_ *smtp.Conn) {
found = true
})
if !found {
Expand Down
2 changes: 1 addition & 1 deletion maddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func InitDirs() error {
}

func ensureDirectoryWritable(path string) error {
if err := os.MkdirAll(path, 0700); err != nil {
if err := os.MkdirAll(path, 0o700); err != nil {
return err
}

Expand Down
4 changes: 1 addition & 3 deletions systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ const (
SDStopping = "STOPPING=1"
)

var (
ErrNoNotifySock = errors.New("no systemd socket")
)
var ErrNoNotifySock = errors.New("no systemd socket")

func sdNotifySock() (*net.UnixConn, error) {
sockAddr := os.Getenv("NOTIFY_SOCKET")
Expand Down
1 change: 0 additions & 1 deletion tests/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ func TestPerIPConcurrency(tt *testing.T) {
c1.Writeln("MAIL FROM:<[email protected]")
// Temporary error due to lock timeout.
c1.ExpectPattern("451 *")

}
4 changes: 2 additions & 2 deletions tests/replace_addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestReplaceAddr_Rcpt(tt *testing.T) {
}`)

// FIXME: Not implemented
//test("external", `
// test("external", `
// hostname mx.maddy.test
// tls off

Expand Down Expand Up @@ -212,7 +212,7 @@ func TestReplaceAddr_Sender(tt *testing.T) {
}
}`)
// FIXME: Not implemented
//test("external", `
// test("external", `
// hostname mx.maddy.test
// tls off

Expand Down
2 changes: 1 addition & 1 deletion tests/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestSPF_DMARCDefer(tt *testing.T) {
defer conn.Close()
conn.SMTPNegotation("localhost", nil, nil)

msg := func(fromEnv, fromHdr string, bodyRespPattern string) {
msg := func(fromEnv, fromHdr, bodyRespPattern string) {
tt.Helper()

conn.Writeln("MAIL FROM:<" + fromEnv + ">")
Expand Down
Loading

0 comments on commit b8d8ca6

Please sign in to comment.