Skip to content

Commit

Permalink
Use type switch with assignment syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
moredure authored Apr 2, 2022
1 parent c0c7ebb commit f20f78e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ type Notification struct {

// MarshalJSON converts the notification payload to JSON.
func (n *Notification) MarshalJSON() ([]byte, error) {
switch n.Payload.(type) {
switch payload := n.Payload.(type) {
case string:
return []byte(n.Payload.(string)), nil
return []byte(payload), nil
case []byte:
return n.Payload.([]byte), nil
return payload, nil
default:
return json.Marshal(n.Payload)
return json.Marshal(payload)
}
}

0 comments on commit f20f78e

Please sign in to comment.