Skip to content

Commit 9ac2d3a

Browse files
committed
Updated postmark package to use CTX
1 parent cd3bc50 commit 9ac2d3a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

postmark.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package gomail
22

33
import (
44
"bufio"
5+
"context"
56
"encoding/base64"
67
"fmt"
7-
"io/ioutil"
8+
"io"
89
"log"
910
"strings"
1011

@@ -13,11 +14,11 @@ import (
1314

1415
// postmarkInterface is an interface for Postmark/mocking
1516
type postmarkInterface interface {
16-
SendEmail(email postmark.Email) (postmark.EmailResponse, error)
17+
SendEmail(ctx context.Context, email postmark.Email) (postmark.EmailResponse, error)
1718
}
1819

1920
// sendViaPostmark sends an email using the Postmark service
20-
func sendViaPostmark(client postmarkInterface, email *Email) (err error) {
21+
func sendViaPostmark(ctx context.Context, client postmarkInterface, email *Email) (err error) {
2122

2223
// Create the email struct
2324
postmarkEmail := postmark.Email{
@@ -73,7 +74,7 @@ func sendViaPostmark(client postmarkInterface, email *Email) (err error) {
7374
// Read all content from the attachment
7475
reader := bufio.NewReader(attachment.FileReader)
7576
var content []byte
76-
if content, err = ioutil.ReadAll(reader); err != nil {
77+
if content, err = io.ReadAll(reader); err != nil {
7778
return
7879
}
7980

@@ -96,7 +97,7 @@ func sendViaPostmark(client postmarkInterface, email *Email) (err error) {
9697

9798
// Send the email
9899
var resp postmark.EmailResponse
99-
if resp, err = client.SendEmail(postmarkEmail); err != nil {
100+
if resp, err = client.SendEmail(ctx, postmarkEmail); err != nil {
100101
return
101102
}
102103

postmark_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gomail
22

33
import (
4+
"context"
45
"fmt"
56
"net/http"
67
"os"
@@ -13,7 +14,7 @@ import (
1314
type mockPostmarkInterface struct{}
1415

1516
// SendEmail is for mocking
16-
func (m *mockPostmarkInterface) SendEmail(email postmark.Email) (postmark.EmailResponse, error) {
17+
func (m *mockPostmarkInterface) SendEmail(_ context.Context, email postmark.Email) (postmark.EmailResponse, error) {
1718

1819
// Success
1920
if email.To == "[email protected]" {
@@ -96,7 +97,7 @@ func TestSendViaPostmark(t *testing.T) {
9697
email.RecipientsCc = []string{test.input}
9798
email.RecipientsBcc = []string{test.input}
9899
email.ReplyToAddress = test.input
99-
if err = sendViaPostmark(client, email); err != nil && !test.expectedError {
100+
if err = sendViaPostmark(context.Background(), client, email); err != nil && !test.expectedError {
100101
t.Fatalf("%s Failed: expected to NOT throw an error, inputted and [%s], error [%s]", t.Name(), test.input, err.Error())
101102
} else if err == nil && test.expectedError {
102103
t.Fatalf("%s Failed: expected to throw an error, inputted and [%s]", t.Name(), test.input)

0 commit comments

Comments
 (0)