diff --git a/gorush/worker.go b/gorush/worker.go index 2c7c031..734d1f7 100644 --- a/gorush/worker.go +++ b/gorush/worker.go @@ -13,15 +13,20 @@ func InitWorkers(workerNum int64, queueNum int64) { } } +// SendNotification is send message to iOS or Android +func SendNotification(msg PushNotification) { + switch msg.Platform { + case PlatFormIos: + PushToIOS(msg) + case PlatFormAndroid: + PushToAndroid(msg) + } +} + func startWorker() { for { notification := <-QueueNotification - switch notification.Platform { - case PlatFormIos: - PushToIOS(notification) - case PlatFormAndroid: - PushToAndroid(notification) - } + SendNotification(notification) } } diff --git a/rpc/server.go b/rpc/server.go index c03d90b..d54315b 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -29,16 +29,10 @@ func (s *server) Send(ctx context.Context, in *pb.NotificationRequest) (*pb.Noti APIKey: in.Key, } - success := false - switch notification.Platform { - case gorush.PlatFormIos: - success = gorush.PushToIOS(notification) - case gorush.PlatFormAndroid: - success = gorush.PushToAndroid(notification) - } + gorush.SendNotification(notification) return &pb.NotificationReply{ - Success: success, + Success: false, Counts: int32(len(notification.Tokens)), }, nil }