From c1006768d85741c11954310177c1db7acc0f5f3c Mon Sep 17 00:00:00 2001 From: Dorian Selimovic Date: Fri, 7 Aug 2020 11:14:05 +0200 Subject: [PATCH 1/2] add request options to send mail methods --- mailjet_client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mailjet_client.go b/mailjet_client.go index ebf8e13..2cff0ec 100644 --- a/mailjet_client.go +++ b/mailjet_client.go @@ -6,6 +6,7 @@ package mailjet import ( "bytes" + "context" "fmt" "encoding/json" @@ -202,9 +203,9 @@ func (c *Client) Delete(mr *Request) (err error) { } // SendMail send mail via API. -func (c *Client) SendMail(data *InfoSendMail) (res *SentResult, err error) { +func (c *Client) SendMail(data *InfoSendMail, options ...RequestOptions) (res *SentResult, err error) { url := c.apiBase + "/send/message" - req, err := createRequest("POST", url, data, nil) + req, err := createRequest("POST", url, data, nil, options...) if err != nil { return res, err } @@ -237,9 +238,9 @@ func buildMessage(header textproto.MIMEHeader, content []byte) []byte { } // SendMailV31 sends a mail to the send API v3.1 -func (c *Client) SendMailV31(data *MessagesV31) (*ResultsV31, error) { +func (c *Client) SendMailV31(data *MessagesV31, options ...RequestOptions) (*ResultsV31, error) { url := c.apiBase + ".1/send" - req, err := createRequest("POST", url, data, nil) + req, err := createRequest("POST", url, data, nil, options...) if err != nil { return nil, err } From 7cb4ca5db1dbd0d35d69e9459a5422e0af2fc4fe Mon Sep 17 00:00:00 2001 From: Dorian Selimovic Date: Fri, 7 Aug 2020 11:14:35 +0200 Subject: [PATCH 2/2] create WithContext request option --- mailjet_client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mailjet_client.go b/mailjet_client.go index 2cff0ec..496a350 100644 --- a/mailjet_client.go +++ b/mailjet_client.go @@ -96,6 +96,13 @@ func Filter(key, value string) RequestOptions { } } +// WithContext sets the request context +func WithContext(ctx context.Context) RequestOptions { + return func(req *http.Request) { + *req = *(req.WithContext(ctx)) + } +} + // SortOrder defines the order of the result. type SortOrder int