diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..2d0a327 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2022 Winni Neessen +# +# SPDX-License-Identifier: CC0-1.0 + +name: golangci-lint +on: + push: + tags: + - v* + branches: + - main + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.gitignore b/.gitignore index 0d4d42d..b6f3875 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ # Local testfiles and auth data .auth -cmd/* +examples/* # SonarQube .scannerwork/ diff --git a/.golangci.toml b/.golangci.toml new file mode 100644 index 0000000..7d1b888 --- /dev/null +++ b/.golangci.toml @@ -0,0 +1,11 @@ +## SPDX-FileCopyrightText: 2022 Winni Neessen +## +## SPDX-License-Identifier: MIT + +[run] +go = "1.16" +tests = true + +[linters] +enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder", + "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file diff --git a/auth/auth_test.go b/auth/auth_test.go index e1a57b2..75875af 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -20,9 +20,13 @@ func TestAuth(t *testing.T) { } authTests := []authTest{ - {LoginAuth("user", "pass", "testserver"), - []string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, "LOGIN", - []string{"", "user", "pass", "", ""}, []bool{false, false, false, true}}, + { + LoginAuth("user", "pass", "testserver"), + []string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, + "LOGIN", + []string{"", "user", "pass", "", ""}, + []bool{false, false, false, true}, + }, } testLoop: diff --git a/client.go b/client.go index 9fb5301..eb608bb 100644 --- a/client.go +++ b/client.go @@ -9,12 +9,13 @@ import ( "crypto/tls" "errors" "fmt" - "github.com/wneessen/go-mail/auth" "net" "net/smtp" "os" "strings" "time" + + "github.com/wneessen/go-mail/auth" ) // Defaults @@ -504,7 +505,7 @@ func (c *Client) Send(ml ...*Msg) error { } if err := c.Reset(); err != nil { - return fmt.Errorf("sending RSET command failed: %s", err) + return fmt.Errorf("sending RSET command failed: %w", err) } if err := c.checkConn(); err != nil { return fmt.Errorf("failed to check server connection: %w", err) @@ -555,7 +556,7 @@ func (c *Client) DialAndSendWithContext(ctx context.Context, ml ...*Msg) error { return fmt.Errorf("send failed: %w", err) } if err := c.Close(); err != nil { - return fmt.Errorf("failed to close connction: %s", err) + return fmt.Errorf("failed to close connction: %w", err) } return nil } diff --git a/client_test.go b/client_test.go index d7e568a..645d142 100644 --- a/client_test.go +++ b/client_test.go @@ -8,11 +8,12 @@ import ( "context" "crypto/tls" "fmt" - "github.com/wneessen/go-mail/auth" "net/smtp" "os" "testing" "time" + + "github.com/wneessen/go-mail/auth" ) // DefaultHost is used as default hostname for the Client @@ -89,9 +90,11 @@ func TestNewClientWithOptions(t *testing.T) { {"WithTLSConfig()", WithTLSConfig(&tls.Config{}), false}, {"WithTLSConfig(); config is nil", WithTLSConfig(nil), true}, {"WithSMTPAuth()", WithSMTPAuth(SMTPAuthLogin), false}, - {"WithSMTPAuthCustom()", + { + "WithSMTPAuthCustom()", WithSMTPAuthCustom(smtp.PlainAuth("", "", "", "")), - false}, + false, + }, {"WithUsername()", WithUsername("test"), false}, {"WithPassword()", WithPassword("test"), false}, {"WithDSN()", WithDSN(), false}, @@ -99,8 +102,10 @@ func TestNewClientWithOptions(t *testing.T) { {"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true}, {"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false}, {"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true}, - {"WithDSNRcptNotifyType() NEVER combination", - WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true}, + { + "WithDSNRcptNotifyType() NEVER combination", + WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -796,7 +801,6 @@ func TestClient_DialSendCloseBroken(t *testing.T) { } }) } - } // TestClient_DialSendCloseBrokenWithDSN tests the Dial(), Send() and Close() method of Client with @@ -857,7 +861,6 @@ func TestClient_DialSendCloseBrokenWithDSN(t *testing.T) { } }) } - } // TestClient_auth tests the Dial(), Send() and Close() method of Client with broken settings @@ -948,10 +951,10 @@ func getTestConnection(auth bool) (*Client, error) { } } if err := c.DialWithContext(context.Background()); err != nil { - return c, fmt.Errorf("connection to test server failed: %s", err) + return c, fmt.Errorf("connection to test server failed: %w", err) } if err := c.Close(); err != nil { - return c, fmt.Errorf("disconnect from test server failed: %s", err) + return c, fmt.Errorf("disconnect from test server failed: %w", err) } return c, nil } @@ -985,10 +988,10 @@ func getTestConnectionWithDSN(auth bool) (*Client, error) { } } if err := c.DialWithContext(context.Background()); err != nil { - return c, fmt.Errorf("connection to test server failed: %s", err) + return c, fmt.Errorf("connection to test server failed: %w", err) } if err := c.Close(); err != nil { - return c, fmt.Errorf("disconnect from test server failed: %s", err) + return c, fmt.Errorf("disconnect from test server failed: %w", err) } return c, nil } diff --git a/doc_test.go b/doc_test.go index 8a71f11..dbf3604 100644 --- a/doc_test.go +++ b/doc_test.go @@ -7,10 +7,11 @@ package mail_test import ( "context" "fmt" - "github.com/wneessen/go-mail" "os" "text/template" "time" + + "github.com/wneessen/go-mail" ) // Code example for the NewClient method diff --git a/encoding.go b/encoding.go index 3fd20e0..f10a903 100644 --- a/encoding.go +++ b/encoding.go @@ -132,7 +132,7 @@ const ( // List of MIME versions const ( - //Mime10 is the MIME Version 1.0 + // Mime10 is the MIME Version 1.0 Mime10 MIMEVersion = "1.0" )