diff --git a/go.mod b/go.mod index 18be4e8..51e53f1 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/go-redis/redis/v7 v7.4.0 github.com/golang/protobuf v1.5.1 github.com/google/flatbuffers v2.0.0+incompatible // indirect + github.com/json-iterator/go v1.1.10 github.com/mattn/go-isatty v0.0.12 github.com/mitchellh/mapstructure v1.4.1 github.com/msalihkarakasli/go-hms-push v0.0.0-20200616114002-91cd23dfeed4 diff --git a/gorush/feedback.go b/gorush/feedback.go index 7bc7a9e..27c6adf 100644 --- a/gorush/feedback.go +++ b/gorush/feedback.go @@ -2,7 +2,6 @@ package gorush import ( "bytes" - "encoding/json" "errors" "net" "net/http" diff --git a/gorush/notification.go b/gorush/notification.go index 11f4db6..1a09a12 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -12,9 +12,13 @@ import ( "github.com/appleboy/gorush/config" "github.com/appleboy/gorush/core" "github.com/appleboy/gorush/logx" + + jsoniter "github.com/json-iterator/go" "github.com/msalihkarakasli/go-hms-push/push/model" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + // D provide string array type D map[string]interface{} @@ -133,6 +137,15 @@ func (p *PushNotification) AddLog(log logx.LogPushEntry) { } } +// Bytes for queue message +func (p *PushNotification) Bytes() []byte { + b, err := json.Marshal(p) + if err != nil { + panic(err) + } + return b +} + // IsTopic check if message format is topic for FCM // ref: https://firebase.google.com/docs/cloud-messaging/send-message#topic-http-post-request func (p *PushNotification) IsTopic() bool { diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index f9e1404..457fe77 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -1,7 +1,6 @@ package gorush import ( - "encoding/json" "log" "net/http" "net/url" diff --git a/gorush/notification_hms.go b/gorush/notification_hms.go index c0668f1..c4f315d 100644 --- a/gorush/notification_hms.go +++ b/gorush/notification_hms.go @@ -2,7 +2,6 @@ package gorush import ( "context" - "encoding/json" "errors" "sync"