Avoid panic when push messages are empty or nil (#13751)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3049378506
Коммит
682a1d5d15
@@ -5,6 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
@@ -83,16 +84,26 @@ func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func PushNotificationFromJson(data io.Reader) *PushNotification {
|
||||
func PushNotificationFromJson(data io.Reader) (*PushNotification, error) {
|
||||
if data == nil {
|
||||
return nil, errors.New("push notification data can't be nil")
|
||||
}
|
||||
var me *PushNotification
|
||||
json.NewDecoder(data).Decode(&me)
|
||||
return me
|
||||
if err := json.NewDecoder(data).Decode(&me); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return me, nil
|
||||
}
|
||||
|
||||
func PushNotificationAckFromJson(data io.Reader) *PushNotificationAck {
|
||||
func PushNotificationAckFromJson(data io.Reader) (*PushNotificationAck, error) {
|
||||
if data == nil {
|
||||
return nil, errors.New("push notification data can't be nil")
|
||||
}
|
||||
var ack *PushNotificationAck
|
||||
json.NewDecoder(data).Decode(&ack)
|
||||
return ack
|
||||
if err := json.NewDecoder(data).Decode(&ack); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ack, nil
|
||||
}
|
||||
|
||||
func (ack *PushNotificationAck) ToJson() string {
|
||||
|
||||
Ссылка в новой задаче
Block a user