Skip to content

Commit

Permalink
DE-1356 revive: use-any (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Dec 7, 2024
1 parent 8e3c3ac commit 6ec38d2
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 107 deletions.
11 changes: 5 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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.
Expand All @@ -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 {
Expand All @@ -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"`
}

//
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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"`
}

//
Expand Down
8 changes: 4 additions & 4 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[email protected]", []interface{}{
return mg.CreateMemberList(ctx, nil, "[email protected]", []any{
mailgun.Member{
Address: "[email protected]",
Name: "Alice's debugging account",
Expand All @@ -86,7 +86,7 @@ func AddListMembers(domain, apiKey string) error {
Address: "[email protected]",
// 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",
},
},
Expand Down Expand Up @@ -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("[email protected]", map[string]interface{}{
m.AddRecipientAndVariables("[email protected]", map[string]any{
"first": "bob",
"id": 1,
})

m.AddRecipientAndVariables("[email protected]", map[string]interface{}{
m.AddRecipientAndVariables("[email protected]", map[string]any{
"first": "alice",
"id": 2,
})
Expand Down
6 changes: 3 additions & 3 deletions httphelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type urlEncodedPayload struct {
}

type jsonEncodedPayload struct {
payload interface{}
payload any
}

func newHTTPRequest(uri string) *httpRequest {
Expand All @@ -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}
}

Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion mailgun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions mailing_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestMailingListMembers(t *testing.T) {
require.NoError(t, mg.DeleteMember(ctx, "[email protected]", address))
assert.Equal(t, startCount, countMembers())

err = mg.CreateMemberList(ctx, nil, address, []interface{}{
err = mg.CreateMemberList(ctx, nil, address, []any{
mailgun.Member{
Address: "[email protected]",
Name: "Joe's debugging account",
Expand All @@ -80,7 +80,7 @@ func TestMailingListMembers(t *testing.T) {
},
mailgun.Member{
Address: "[email protected]",
Vars: map[string]interface{}{
Vars: map[string]any{
"packet-email": "KW9ABC @ BOGBBS-4.#NCA.CA.USA.NOAM",
},
},
Expand Down Expand Up @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions members.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
23 changes: 12 additions & 11 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -437,11 +437,11 @@ func TestAddRecipientAndVariablesError(t *testing.T) {

for i := 0; i < 1000; i++ {
recipient := fmt.Sprintf("recipient_%[email protected]", 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("[email protected]", map[string]interface{}{"id": 1001})
err = m.AddRecipientAndVariables("[email protected]", map[string]any{"id": 1001})
require.EqualError(t, err, "recipient limit exceeded (max 1000)")
}

Expand Down
4 changes: 2 additions & 2 deletions messages_types_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6ec38d2

Please sign in to comment.