From 10e20184379aba4ad63912248aa9e3f4a54aed96 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:42:57 +0200 Subject: [PATCH 1/2] TODO --- messages.go | 1 + 1 file changed, 1 insertion(+) diff --git a/messages.go b/messages.go index d419883..1c83248 100644 --- a/messages.go +++ b/messages.go @@ -767,6 +767,7 @@ func addMessageOptions(dst *FormDataPayload, src SendableMessage) { dst.addValue("o:tag", tag) } for _, campaign := range src.Campaigns() { + // TODO(v5): deprecated - https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Messages/ dst.addValue("o:campaign", campaign) } if src.DKIM() != nil { From dda7c15958f9c94e1dea856604d037017278a0c2 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:45:36 +0200 Subject: [PATCH 2/2] interface{} -> any --- .golangci.yml | 11 ++++----- events/events.go | 48 +++++++++++++++++++-------------------- examples/examples.go | 8 +++---- httphelpers.go | 6 ++--- mailgun.go | 2 +- mailing_lists_test.go | 8 +++---- members.go | 10 ++++---- messages.go | 22 +++++++++--------- messages_test.go | 8 +++---- messages_types_v5.go | 4 ++-- messages_v5.go | 10 ++++---- mock.go | 6 ++--- mock_bounces.go | 8 +++---- mock_complaints.go | 6 ++--- mock_credentials.go | 6 ++--- mock_tags.go | 4 ++-- mock_template_versions.go | 12 +++++----- mock_templates.go | 10 ++++---- mock_unsubscribes.go | 8 +++---- parse.go | 2 +- parse_test.go | 8 +++---- rest_shim.go | 6 ++--- 22 files changed, 106 insertions(+), 107 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 395abf2..f5403dc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -445,12 +445,11 @@ linters-settings: arguments: - allowRegex: "^_" - # TODO(Go1.18+): enable: - # # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any - # - name: use-any - # severity: warning - # disabled: false - # exclude: [""] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any + - name: use-any + severity: warning + disabled: false + exclude: [""] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break - name: useless-break diff --git a/events/events.go b/events/events.go index da26501..7c8d08d 100644 --- a/events/events.go +++ b/events/events.go @@ -52,14 +52,14 @@ type Accepted struct { Message Message `json:"message"` Flags Flags `json:"flags"` - Recipient string `json:"recipient"` - RecipientDomain string `json:"recipient-domain"` - Method string `json:"method"` - OriginatingIP string `json:"originating-ip"` - Tags []string `json:"tags"` - Campaigns []Campaign `json:"campaigns"` - UserVariables interface{} `json:"user-variables"` - Storage Storage `json:"storage"` + Recipient string `json:"recipient"` + RecipientDomain string `json:"recipient-domain"` + Method string `json:"method"` + OriginatingIP string `json:"originating-ip"` + Tags []string `json:"tags"` + Campaigns []Campaign `json:"campaigns"` + UserVariables any `json:"user-variables"` + Storage Storage `json:"storage"` } type Rejected struct { @@ -74,9 +74,9 @@ type Rejected struct { Storage Storage `json:"storage"` Flags Flags `json:"flags"` - Tags []string `json:"tags"` - Campaigns []Campaign `json:"campaigns"` - UserVariables interface{} `json:"user-variables"` + Tags []string `json:"tags"` + Campaigns []Campaign `json:"campaigns"` + UserVariables any `json:"user-variables"` } type Delivered struct { @@ -94,7 +94,7 @@ type Delivered struct { Storage Storage `json:"storage"` DeliveryStatus DeliveryStatus `json:"delivery-status"` - UserVariables interface{} `json:"user-variables"` + UserVariables any `json:"user-variables"` } // Failed - Mailgun could not deliver the email to the recipient email server. @@ -120,9 +120,9 @@ type Failed struct { // - permanent when a message is not delivered; // // - temporary when a message is temporarily rejected by an ESP. - Severity string `json:"severity"` - Reason string `json:"reason"` - UserVariables interface{} `json:"user-variables"` + Severity string `json:"severity"` + Reason string `json:"reason"` + UserVariables any `json:"user-variables"` } type Stored struct { @@ -132,9 +132,9 @@ type Stored struct { Storage Storage `json:"storage"` Flags Flags `json:"flags"` - Tags []string `json:"tags"` - Campaigns []Campaign `json:"campaigns"` - UserVariables interface{} `json:"user-variables"` + Tags []string `json:"tags"` + Campaigns []Campaign `json:"campaigns"` + UserVariables any `json:"user-variables"` } // @@ -156,7 +156,7 @@ type Opened struct { ClientInfo ClientInfo `json:"client-info"` GeoLocation GeoLocation `json:"geolocation"` - UserVariables interface{} `json:"user-variables"` + UserVariables any `json:"user-variables"` } type Clicked struct { @@ -176,7 +176,7 @@ type Clicked struct { ClientInfo ClientInfo `json:"client-info"` GeoLocation GeoLocation `json:"geolocation"` - UserVariables interface{} `json:"user-variables"` + UserVariables any `json:"user-variables"` } type Unsubscribed struct { @@ -194,7 +194,7 @@ type Unsubscribed struct { ClientInfo ClientInfo `json:"client-info"` GeoLocation GeoLocation `json:"geolocation"` - UserVariables interface{} `json:"user-variables"` + UserVariables any `json:"user-variables"` } type Complained struct { @@ -203,9 +203,9 @@ type Complained struct { Message Message `json:"message"` Campaigns []Campaign `json:"campaigns"` - Recipient string `json:"recipient"` - Tags []string `json:"tags"` - UserVariables interface{} `json:"user-variables"` + Recipient string `json:"recipient"` + Tags []string `json:"tags"` + UserVariables any `json:"user-variables"` } // diff --git a/examples/examples.go b/examples/examples.go index e1ac95f..8c43abe 100644 --- a/examples/examples.go +++ b/examples/examples.go @@ -71,7 +71,7 @@ func AddListMembers(domain, apiKey string) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() - return mg.CreateMemberList(ctx, nil, "mailgunList@example.com", []interface{}{ + return mg.CreateMemberList(ctx, nil, "mailgunList@example.com", []any{ mailgun.Member{ Address: "alice@example.com", Name: "Alice's debugging account", @@ -86,7 +86,7 @@ func AddListMembers(domain, apiKey string) error { Address: "joe.hamradio@example.com", // Charlette is a ham radio packet BBS user. // We attach her packet BBS e-mail address as an arbitrary var here. - Vars: map[string]interface{}{ + Vars: map[string]any{ "packet-email": "KW9ABC @ BOGUS-4.#NCA.CA.USA.NOAM", }, }, @@ -853,12 +853,12 @@ func SendTemplateMessage(domain, apiKey string) (string, error) { // Set template to be applied to this message. m.SetTemplate("my-template") - m.AddRecipientAndVariables("bob@example.com", map[string]interface{}{ + m.AddRecipientAndVariables("bob@example.com", map[string]any{ "first": "bob", "id": 1, }) - m.AddRecipientAndVariables("alice@example.com", map[string]interface{}{ + m.AddRecipientAndVariables("alice@example.com", map[string]any{ "first": "alice", "id": 2, }) diff --git a/httphelpers.go b/httphelpers.go index dc02040..e164f67 100644 --- a/httphelpers.go +++ b/httphelpers.go @@ -73,7 +73,7 @@ type urlEncodedPayload struct { } type jsonEncodedPayload struct { - payload interface{} + payload any } func newHTTPRequest(uri string) *httpRequest { @@ -96,7 +96,7 @@ func (r *httpRequest) setBasicAuth(user, password string) { r.BasicAuthPassword = password } -func newJSONEncodedPayload(payload interface{}) *jsonEncodedPayload { +func newJSONEncodedPayload(payload any) *jsonEncodedPayload { return &jsonEncodedPayload{payload: payload} } @@ -142,7 +142,7 @@ func (f *urlEncodedPayload) getValues() []keyValuePair { return f.Values } -func (r *httpResponse) parseFromJSON(v interface{}) error { +func (r *httpResponse) parseFromJSON(v any) error { return json.Unmarshal(r.Data, v) } diff --git a/mailgun.go b/mailgun.go index 24271ca..e2e3aea 100644 --- a/mailgun.go +++ b/mailgun.go @@ -225,7 +225,7 @@ type Mailgun interface { ListMembers(address string, opts *ListOptions) *MemberListIterator GetMember(ctx context.Context, MemberAddr, listAddr string) (Member, error) CreateMember(ctx context.Context, merge bool, addr string, prototype Member) error - CreateMemberList(ctx context.Context, subscribed *bool, addr string, newMembers []interface{}) error + CreateMemberList(ctx context.Context, subscribed *bool, addr string, newMembers []any) error UpdateMember(ctx context.Context, Member, list string, prototype Member) (Member, error) DeleteMember(ctx context.Context, Member, list string) error diff --git a/mailing_lists_test.go b/mailing_lists_test.go index f49298b..c18f40e 100644 --- a/mailing_lists_test.go +++ b/mailing_lists_test.go @@ -67,7 +67,7 @@ func TestMailingListMembers(t *testing.T) { require.NoError(t, mg.DeleteMember(ctx, "joe@example.com", address)) assert.Equal(t, startCount, countMembers()) - err = mg.CreateMemberList(ctx, nil, address, []interface{}{ + err = mg.CreateMemberList(ctx, nil, address, []any{ mailgun.Member{ Address: "joe.user1@example.com", Name: "Joe's debugging account", @@ -80,7 +80,7 @@ func TestMailingListMembers(t *testing.T) { }, mailgun.Member{ Address: "joe.user3@example.com", - Vars: map[string]interface{}{ + Vars: map[string]any{ "packet-email": "KW9ABC @ BOGBBS-4.#NCA.CA.USA.NOAM", }, }, @@ -164,9 +164,9 @@ func TestListMailingListRegression(t *testing.T) { require.NoError(t, err) for i := 0; i < 200; i++ { - var vars map[string]interface{} + var vars map[string]any if i == 5 { - vars = map[string]interface{}{"has": "vars"} + vars = map[string]any{"has": "vars"} } err := mg.CreateMember(ctx, false, address, mailgun.Member{ diff --git a/members.go b/members.go index 2bf83e9..0bd0771 100644 --- a/members.go +++ b/members.go @@ -29,10 +29,10 @@ var ( // A Member structure represents a member of the mailing list. // The Vars field can represent any JSON-encodable data. type Member struct { - Address string `json:"address,omitempty"` - Name string `json:"name,omitempty"` - Subscribed *bool `json:"subscribed,omitempty"` - Vars map[string]interface{} `json:"vars,omitempty"` + Address string `json:"address,omitempty"` + Name string `json:"name,omitempty"` + Subscribed *bool `json:"subscribed,omitempty"` + Vars map[string]any `json:"vars,omitempty"` } type memberListResponse struct { @@ -243,7 +243,7 @@ func (mg *MailgunImpl) DeleteMember(ctx context.Context, member, addr string) er // If a simple slice of strings is passed, each string refers to the member's e-mail address. // Otherwise, each Member needs to have at least the Address field filled out. // Other fields are optional, but may be set according to your needs. -func (mg *MailgunImpl) CreateMemberList(ctx context.Context, u *bool, addr string, newMembers []interface{}) error { +func (mg *MailgunImpl) CreateMemberList(ctx context.Context, u *bool, addr string, newMembers []any) error { r := newHTTPRequest(generateMemberApiUrl(mg, listsEndpoint, addr) + ".json") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) diff --git a/messages.go b/messages.go index 1c83248..359533f 100644 --- a/messages.go +++ b/messages.go @@ -41,8 +41,8 @@ type Message struct { trackingOpens *bool headers map[string]string variables map[string]string - templateVariables map[string]interface{} - recipientVariables map[string]map[string]interface{} + templateVariables map[string]any + recipientVariables map[string]map[string]any domain string templateVersionTag string templateRenderText bool @@ -285,11 +285,11 @@ func (m *Message) Variables() map[string]string { return m.variables } -func (m *Message) TemplateVariables() map[string]interface{} { +func (m *Message) TemplateVariables() map[string]any { return m.templateVariables } -func (m *Message) RecipientVariables() map[string]map[string]interface{} { +func (m *Message) RecipientVariables() map[string]map[string]any { return m.recipientVariables } @@ -364,14 +364,14 @@ func (m *Message) AddRecipient(recipient string) error { // AddRecipientAndVariables appends a receiver to the To: header of a message, // and as well attaches a set of variables relevant for this recipient. // It will return an error if the limit of recipients have been exceeded for this message -func (m *Message) AddRecipientAndVariables(r string, vars map[string]interface{}) error { +func (m *Message) AddRecipientAndVariables(r string, vars map[string]any) error { if m.RecipientCount() >= MaxNumberOfRecipients { return fmt.Errorf("recipient limit exceeded (max %d)", MaxNumberOfRecipients) } m.to = append(m.to, r) if vars != nil { if m.recipientVariables == nil { - m.recipientVariables = make(map[string]map[string]interface{}) + m.recipientVariables = make(map[string]map[string]any) } m.recipientVariables[r] = vars } @@ -574,7 +574,7 @@ func (m *Message) AddHeader(header, value string) { // AddVariable lets you associate a set of variables with messages you send, // which Mailgun can use to, in essence, complete form-mail. // Refer to the Mailgun documentation for more information. -func (m *Message) AddVariable(variable string, value interface{}) error { +func (m *Message) AddVariable(variable string, value any) error { if m.variables == nil { m.variables = make(map[string]string) } @@ -597,9 +597,9 @@ func (m *Message) AddVariable(variable string, value interface{}) error { // AddTemplateVariable adds a template variable to the map of template variables, replacing the variable if it is already there. // This is used for server-side message templates and can nest arbitrary values. At send time, the resulting map will be converted into // a JSON string and sent as a header in the X-Mailgun-Variables header. -func (m *Message) AddTemplateVariable(variable string, value interface{}) error { +func (m *Message) AddTemplateVariable(variable string, value any) error { if m.templateVariables == nil { - m.templateVariables = make(map[string]interface{}) + m.templateVariables = make(map[string]any) } m.templateVariables[variable] = value return nil @@ -646,8 +646,8 @@ type SendableMessage interface { TrackingOpens() *bool Headers() map[string]string Variables() map[string]string - TemplateVariables() map[string]interface{} - RecipientVariables() map[string]map[string]interface{} + TemplateVariables() map[string]any + RecipientVariables() map[string]map[string]any TemplateVersionTag() string TemplateRenderText() bool RequireTLS() bool diff --git a/messages_test.go b/messages_test.go index 953567d..408297e 100644 --- a/messages_test.go +++ b/messages_test.go @@ -281,7 +281,7 @@ func TestSendMGBatchRecipientVariables(t *testing.T) { ctx := context.Background() m := mailgun.NewMessage(fromUser, exampleSubject, templateText) - err = m.AddRecipientAndVariables(toUser, map[string]interface{}{ + err = m.AddRecipientAndVariables(toUser, map[string]any{ "name": "Joe Cool Example", "table": 42, }) @@ -374,7 +374,7 @@ func TestSendMGMessageVariables(t *testing.T) { ) var ( exampleMapVarVal = map[string]string{"test": "123"} - exampleTemplateVariable = map[string]interface{}{ + exampleTemplateVariable = map[string]any{ "key": map[string]string{ "nested": "yes", "status": "test", @@ -437,11 +437,11 @@ func TestAddRecipientAndVariablesError(t *testing.T) { for i := 0; i < 1000; i++ { recipient := fmt.Sprintf("recipient_%d@example.com", i) - err = m.AddRecipientAndVariables(recipient, map[string]interface{}{"id": i}) + err = m.AddRecipientAndVariables(recipient, map[string]any{"id": i}) require.NoError(t, err) } - err = m.AddRecipientAndVariables("recipient_1001@example.com", map[string]interface{}{"id": 1001}) + err = m.AddRecipientAndVariables("recipient_1001@example.com", map[string]any{"id": 1001}) require.EqualError(t, err, "recipient limit exceeded (max 1000)") } diff --git a/messages_types_v5.go b/messages_types_v5.go index 5b196c2..eeefa99 100644 --- a/messages_types_v5.go +++ b/messages_types_v5.go @@ -28,8 +28,8 @@ type commonMessageV5 struct { trackingOpens *bool headers map[string]string variables map[string]string - templateVariables map[string]interface{} - recipientVariables map[string]map[string]interface{} + templateVariables map[string]any + recipientVariables map[string]map[string]any templateVersionTag string templateRenderText bool requireTLS bool diff --git a/messages_v5.go b/messages_v5.go index 62c8d1f..23cca5e 100644 --- a/messages_v5.go +++ b/messages_v5.go @@ -220,7 +220,7 @@ func (m *commonMessageV5) AddHeader(header, value string) { // AddVariable lets you associate a set of variables with messages you send, // which Mailgun can use to, in essence, complete form-mail. // Refer to the Mailgun documentation for more information. -func (m *commonMessageV5) AddVariable(variable string, value interface{}) error { +func (m *commonMessageV5) AddVariable(variable string, value any) error { if m.variables == nil { m.variables = make(map[string]string) } @@ -243,9 +243,9 @@ func (m *commonMessageV5) AddVariable(variable string, value interface{}) error // AddTemplateVariable adds a template variable to the map of template variables, replacing the variable if it is already there. // This is used for server-side message templates and can nest arbitrary values. At send time, the resulting map will be converted into // a JSON string and sent as a header in the X-Mailgun-Variables header. -func (m *commonMessageV5) AddTemplateVariable(variable string, value interface{}) error { +func (m *commonMessageV5) AddTemplateVariable(variable string, value any) error { if m.templateVariables == nil { - m.templateVariables = make(map[string]interface{}) + m.templateVariables = make(map[string]any) } m.templateVariables[variable] = value return nil @@ -270,14 +270,14 @@ func (m *plainMessageV5) AddRecipient(recipient string) error { // AddRecipientAndVariables appends a receiver to the To: header of a message, // and as well attaches a set of variables relevant for this recipient. // It will return an error if the limit of recipients have been exceeded for this message -func (m *plainMessageV5) AddRecipientAndVariables(r string, vars map[string]interface{}) error { +func (m *plainMessageV5) AddRecipientAndVariables(r string, vars map[string]any) error { if m.RecipientCount() >= MaxNumberOfRecipients { return fmt.Errorf("recipient limit exceeded (max %d)", MaxNumberOfRecipients) } m.to = append(m.to, r) if vars != nil { if m.recipientVariables == nil { - m.recipientVariables = make(map[string]map[string]interface{}) + m.recipientVariables = make(map[string]map[string]any) } m.recipientVariables[r] = vars } diff --git a/mock.go b/mock.go index 1120318..6f6ee2e 100644 --- a/mock.go +++ b/mock.go @@ -166,7 +166,7 @@ func (ms *mockServer) URL() string { return ms.srv.URL + "/v3" } -func toJSON(w http.ResponseWriter, obj interface{}) { +func toJSON(w http.ResponseWriter, obj any) { if err := json.NewEncoder(w).Encode(obj); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } @@ -202,12 +202,12 @@ func stringToInt(v string) int { return int(result) } -func stringToMap(v string) map[string]interface{} { +func stringToMap(v string) map[string]any { if v == "" { return nil } - result := make(map[string]interface{}) + result := make(map[string]any) err := json.Unmarshal([]byte(v), &result) if err != nil { panic(err) diff --git a/mock_bounces.go b/mock_bounces.go index 099b3c0..ecea4cb 100644 --- a/mock_bounces.go +++ b/mock_bounces.go @@ -158,7 +158,7 @@ func (ms *mockServer) createBounce(w http.ResponseWriter, r *http.Request) { } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address has been added to the bounces table", "address": fmt.Sprint(bounces), }) @@ -172,14 +172,14 @@ func (ms *mockServer) deleteBounce(w http.ResponseWriter, r *http.Request) { if bounce.Address == chi.URLParam(r, "address") { ms.bounces = append(ms.bounces[:i], ms.bounces[i+1:len(ms.bounces)]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Bounce has been removed", }) return } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address not found in bounces table", }) } @@ -190,7 +190,7 @@ func (ms *mockServer) deleteBouncesList(w http.ResponseWriter, r *http.Request) ms.bounces = []Bounce{} - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "All bounces has been deleted", }) } diff --git a/mock_complaints.go b/mock_complaints.go index f09b906..fdc9f98 100644 --- a/mock_complaints.go +++ b/mock_complaints.go @@ -151,7 +151,7 @@ func (ms *mockServer) createComplaint(w http.ResponseWriter, r *http.Request) { } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address has been added to the complaints table", "address": fmt.Sprint(complaints), }) @@ -165,14 +165,14 @@ func (ms *mockServer) deleteComplaint(w http.ResponseWriter, r *http.Request) { if complaint.Address == chi.URLParam(r, "address") { ms.complaints = append(ms.complaints[:i], ms.complaints[i+1:len(ms.complaints)]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Complaint has been removed", }) return } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address not found in complaints table", }) return diff --git a/mock_credentials.go b/mock_credentials.go index 0e2a4c6..0e9b6ff 100644 --- a/mock_credentials.go +++ b/mock_credentials.go @@ -94,7 +94,7 @@ func (ms *mockServer) createCredential(w http.ResponseWriter, r *http.Request) { ms.credentials = append(ms.credentials, Credential{Login: login, Password: password, CreatedAt: RFC2822Time(time.Now())}) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Credentials created", }) } @@ -112,7 +112,7 @@ func (ms *mockServer) deleteCredential(w http.ResponseWriter, r *http.Request) { } ms.credentials = append(ms.credentials[:i], ms.credentials[i+1:]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Credentials have been deleted", "spec": login, }) @@ -145,7 +145,7 @@ func (ms *mockServer) updateCredential(w http.ResponseWriter, r *http.Request) { for i, credential := range ms.credentials { if credential.Login == login || credential.Login == login+"@"+domain { ms.credentials[i].Password = password - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Password changed", }) return diff --git a/mock_tags.go b/mock_tags.go index 6dc1706..09e0d85 100644 --- a/mock_tags.go +++ b/mock_tags.go @@ -128,7 +128,7 @@ func (ms *mockServer) createUpdateTags(w http.ResponseWriter, r *http.Request) { ms.tags = append(ms.tags, Tag{Value: tag, Description: description}) } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Tag updated", }) } @@ -143,7 +143,7 @@ func (ms *mockServer) deleteTags(w http.ResponseWriter, r *http.Request) { } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Tag deleted", }) } diff --git a/mock_template_versions.go b/mock_template_versions.go index d0a862e..f388100 100644 --- a/mock_template_versions.go +++ b/mock_template_versions.go @@ -189,7 +189,7 @@ func (ms *mockServer) createTemplateVersion(w http.ResponseWriter, r *http.Reque ms.templateVersions[templateName] = append(ms.templateVersions[templateName], newTemplateVersion) template.Version = newTemplateVersion - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "new version of the template has been stored", "template": template, }) @@ -246,7 +246,7 @@ func (ms *mockServer) updateTemplateVersion(w http.ResponseWriter, r *http.Reque if len(active) != 0 { if active == "yes" { templateVersion.Active = true - for i := range ms.templateVersions[templateName] { //every other template version become not active + for i := range ms.templateVersions[templateName] { // every other template version become not active if i == templateVersionIndex { continue } @@ -263,9 +263,9 @@ func (ms *mockServer) updateTemplateVersion(w http.ResponseWriter, r *http.Reque } ms.templateVersions[templateName][templateVersionIndex] = templateVersion - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "version has been updated", - "template": map[string]interface{}{ + "template": map[string]any{ "name": templateName, "version": map[string]string{ "tag": templateVersionName, @@ -297,9 +297,9 @@ func (ms *mockServer) deleteTemplateVersion(w http.ResponseWriter, r *http.Reque } w.WriteHeader(http.StatusOK) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "version has been deleted", - "template": map[string]interface{}{ + "template": map[string]any{ "name": templateName, "version": map[string]string{ "tag": templateVersionName, diff --git a/mock_templates.go b/mock_templates.go index 657c8a7..fffea13 100644 --- a/mock_templates.go +++ b/mock_templates.go @@ -150,7 +150,7 @@ func (ms *mockServer) getTemplate(w http.ResponseWriter, r *http.Request) { if template.Name == templateName { if active == "true" { version := ms.getActiveTemplateVersion(templateName) - if version.Active { //active version exists + if version.Active { // active version exists template.Version = version } } @@ -223,7 +223,7 @@ func (ms *mockServer) createTemplate(w http.ResponseWriter, r *http.Request) { } ms.templates = append(ms.templates, template) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "template has been stored", "template": template, }) @@ -252,7 +252,7 @@ func (ms *mockServer) updateTemplate(w http.ResponseWriter, r *http.Request) { for i, template := range ms.templates { if template.Name == name { ms.templates[i].Description = description - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "template has been updated", "template": map[string]string{ "name": name, @@ -263,7 +263,7 @@ func (ms *mockServer) updateTemplate(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(http.StatusNotFound) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "template not found", }) } @@ -278,7 +278,7 @@ func (ms *mockServer) deleteTemplate(w http.ResponseWriter, r *http.Request) { if template.Name == templateName { ms.templates = append(ms.templates[:i], ms.templates[i+1:len(ms.templates)]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "template has been deleted", "template": map[string]string{ "name": templateName, diff --git a/mock_unsubscribes.go b/mock_unsubscribes.go index e8d5ba6..8091763 100644 --- a/mock_unsubscribes.go +++ b/mock_unsubscribes.go @@ -157,7 +157,7 @@ func (ms *mockServer) createUnsubscribe(w http.ResponseWriter, r *http.Request) } } - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address has been added to the unsubscribes table", "address": fmt.Sprint(unsubscribes), }) @@ -181,7 +181,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) } if !addressExist { - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Address not found in unsubscribers table", }) return @@ -195,7 +195,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) } ms.unsubscribes = append(ms.unsubscribes[:i], ms.unsubscribes[i+1:len(ms.unsubscribes)]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Unsubscribe event has been removed", }) return @@ -211,7 +211,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) continue } ms.unsubscribes[i].Tags = append(ms.unsubscribes[i].Tags[:j], ms.unsubscribes[i].Tags[j+1:]...) - toJSON(w, map[string]interface{}{ + toJSON(w, map[string]any{ "message": "Unsubscribe event has been removed", }) return diff --git a/parse.go b/parse.go index 4fdb73f..6d89994 100644 --- a/parse.go +++ b/parse.go @@ -36,7 +36,7 @@ var EventNames = map[string]func() Event{ } // new_ is a universal event "constructor". -func new_(e interface{}) func() Event { +func new_(e any) func() Event { typ := reflect.TypeOf(e) return func() Event { //nolint:revive // unchecked-type-assertion: this func is called on init only, so there should be no runtime panics: diff --git a/parse_test.go b/parse_test.go index b65bdb0..0ee54cc 100644 --- a/parse_test.go +++ b/parse_test.go @@ -101,11 +101,11 @@ func TestParseSuccess(t *testing.T) { // Make sure the second attempt of Parse doesn't overwrite the first event struct. assert.Equal(t, "dude@example.com", event.(*events.Accepted).Recipient) - assert.Equal(t, "value", event.(*events.Accepted).UserVariables.(map[string]interface{})["custom"]) - child := event.(*events.Accepted).UserVariables.(map[string]interface{})["parent"].(map[string]interface{})["child"] + assert.Equal(t, "value", event.(*events.Accepted).UserVariables.(map[string]any)["custom"]) + child := event.(*events.Accepted).UserVariables.(map[string]any)["parent"].(map[string]any)["child"] assert.Equal(t, "user defined variable", child) - aList := event.(*events.Accepted).UserVariables.(map[string]interface{})["a-list"].([]interface{}) - assert.Equal(t, []interface{}{1.0, 2.0, 3.0, 4.0, 5.0}, aList) + aList := event.(*events.Accepted).UserVariables.(map[string]any)["a-list"].([]any) + assert.Equal(t, []any{1.0, 2.0, 3.0, 4.0, 5.0}, aList) } func TestParseSuccessInvalidUserVariables(t *testing.T) { diff --git a/rest_shim.go b/rest_shim.go index 93990e0..57b5ec1 100644 --- a/rest_shim.go +++ b/rest_shim.go @@ -73,7 +73,7 @@ func makeRequest(ctx context.Context, r *httpRequest, method string, p payload) // getResponseFromJSON shim performs a GET request, checking for a positive outcome. // See simplehttp.GetResponseFromJSON for more details. -func getResponseFromJSON(ctx context.Context, r *httpRequest, v interface{}) error { +func getResponseFromJSON(ctx context.Context, r *httpRequest, v any) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makeGetRequest(ctx) if err != nil { @@ -87,7 +87,7 @@ func getResponseFromJSON(ctx context.Context, r *httpRequest, v interface{}) err // postResponseFromJSON shim performs a POST request, checking for a positive outcome. // See simplehttp.PostResponseFromJSON for more details. -func postResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v interface{}) error { +func postResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v any) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makePostRequest(ctx, p) if err != nil { @@ -101,7 +101,7 @@ func postResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v inte // putResponseFromJSON shim performs a PUT request, checking for a positive outcome. // See simplehttp.PutResponseFromJSON for more details. -func putResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v interface{}) error { +func putResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v any) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makePutRequest(ctx, p) if err != nil {