From 333c2dc7ecee0685ad1f2429f091bd4361ef690f Mon Sep 17 00:00:00 2001 From: Mikhail Faraponov <11322032+moredure@users.noreply.github.com> Date: Sat, 2 Apr 2022 23:59:34 +0300 Subject: [PATCH 1/3] Use type switch with assignment syntax (#196) --- notification.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notification.go b/notification.go index 09abe0d5..69bf312d 100644 --- a/notification.go +++ b/notification.go @@ -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) } } From fcd9aedef6f8d4b358dbdaf032364ec6851c0c02 Mon Sep 17 00:00:00 2001 From: Mikhail Faraponov <11322032+moredure@users.noreply.github.com> Date: Sun, 3 Apr 2022 01:18:25 +0300 Subject: [PATCH 2/3] Use POST http constant (#203) --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 7b4420ce..dd7afa3e 100644 --- a/client.go +++ b/client.go @@ -162,7 +162,7 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error } url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken) - req, err := http.NewRequest("POST", url, bytes.NewReader(payload)) + req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload)) if err != nil { return nil, err } From f5dc865a1969a7a71a01a34403e66169d1def5f3 Mon Sep 17 00:00:00 2001 From: Mikhail Faraponov <11322032+moredure@users.noreply.github.com> Date: Sun, 3 Apr 2022 01:25:35 +0300 Subject: [PATCH 3/3] Use if type conditional (#198) In that case if type is much simpler and look better. --- token/token.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/token/token.go b/token/token.go index 0aab81b7..26fec563 100644 --- a/token/token.go +++ b/token/token.go @@ -58,12 +58,10 @@ func AuthKeyFromBytes(bytes []byte) (*ecdsa.PrivateKey, error) { if err != nil { return nil, err } - switch pk := key.(type) { - case *ecdsa.PrivateKey: + if pk, ok := key.(*ecdsa.PrivateKey); ok { return pk, nil - default: - return nil, ErrAuthKeyNotECDSA } + return nil, ErrAuthKeyNotECDSA } // GenerateIfExpired checks to see if the token is about to expire and