chore: rename gorush to notify package (#609)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2021-07-24 01:56:33 +08:00 committed by GitHub
parent ce6e87639a
commit d9947ea44d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 73 additions and 73 deletions

View File

@ -6,7 +6,7 @@ DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
GOFMT ?= gofumpt -l -s -extra
TARGETS ?= linux darwin windows openbsd
TARGETS ?= linux darwin windows
ARCHS ?= amd64
GOFILES := $(shell find . -name "*.go" -type f)
TAGS ?= sqlite

40
main.go
View File

@ -16,8 +16,8 @@ import (
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
"github.com/appleboy/gorush/queue/nsq"
"github.com/appleboy/gorush/queue/simple"
@ -116,7 +116,7 @@ func main() {
}
// Initialize push slots for concurrent iOS pushes
gorush.MaxConcurrentIOSPushes = make(chan struct{}, cfg.Ios.MaxConcurrentPushes)
notify.MaxConcurrentIOSPushes = make(chan struct{}, cfg.Ios.MaxConcurrentPushes)
if opts.Ios.KeyPath != "" {
cfg.Ios.KeyPath = opts.Ios.KeyPath
@ -176,7 +176,7 @@ func main() {
}
if cfg.Core.HTTPProxy != "" {
err = gorush.SetProxy(cfg.Core.HTTPProxy)
err = notify.SetProxy(cfg.Core.HTTPProxy)
if err != nil {
logx.LogError.Fatalf("Set Proxy error: %v", err)
@ -193,7 +193,7 @@ func main() {
// send android notification
if opts.Android.Enabled {
cfg.Android.Enabled = opts.Android.Enabled
req := gorush.PushNotification{
req := notify.PushNotification{
Cfg: cfg,
Platform: core.PlatFormAndroid,
Message: message,
@ -210,7 +210,7 @@ func main() {
req.To = topic
}
err := gorush.CheckMessage(req)
err := notify.CheckMessage(req)
if err != nil {
logx.LogError.Fatal(err)
}
@ -219,7 +219,7 @@ func main() {
return
}
gorush.PushToAndroid(req)
notify.PushToAndroid(req)
return
}
@ -227,7 +227,7 @@ func main() {
// send huawei notification
if opts.Huawei.Enabled {
cfg.Huawei.Enabled = opts.Huawei.Enabled
req := gorush.PushNotification{
req := notify.PushNotification{
Cfg: cfg,
Platform: core.PlatFormHuawei,
Message: message,
@ -244,7 +244,7 @@ func main() {
req.To = topic
}
err := gorush.CheckMessage(req)
err := notify.CheckMessage(req)
if err != nil {
logx.LogError.Fatal(err)
}
@ -253,7 +253,7 @@ func main() {
return
}
gorush.PushToHuawei(req)
notify.PushToHuawei(req)
return
}
@ -265,7 +265,7 @@ func main() {
}
cfg.Ios.Enabled = opts.Ios.Enabled
req := gorush.PushNotification{
req := notify.PushNotification{
Cfg: cfg,
Platform: core.PlatFormIos,
Message: message,
@ -282,7 +282,7 @@ func main() {
req.Topic = topic
}
err := gorush.CheckMessage(req)
err := notify.CheckMessage(req)
if err != nil {
logx.LogError.Fatal(err)
}
@ -291,15 +291,15 @@ func main() {
return
}
if err := gorush.InitAPNSClient(cfg); err != nil {
if err := notify.InitAPNSClient(cfg); err != nil {
return
}
gorush.PushToIOS(req)
notify.PushToIOS(req)
return
}
if err = gorush.CheckPushConf(cfg); err != nil {
if err = notify.CheckPushConf(cfg); err != nil {
logx.LogError.Fatal(err)
}
@ -353,23 +353,23 @@ func main() {
}
})
// gorush.InitQueue(cfg.Core.WorkerNum, cfg.Core.QueueNum)
// gorush.InitWorkers(ctx, wg, cfg.Core.WorkerNum, cfg.Core.QueueNum)
// notify.InitQueue(cfg.Core.WorkerNum, cfg.Core.QueueNum)
// notify.InitWorkers(ctx, wg, cfg.Core.WorkerNum, cfg.Core.QueueNum)
if cfg.Ios.Enabled {
if err = gorush.InitAPNSClient(cfg); err != nil {
if err = notify.InitAPNSClient(cfg); err != nil {
logx.LogError.Fatal(err)
}
}
if cfg.Android.Enabled {
if _, err = gorush.InitFCMClient(cfg, cfg.Android.APIKey); err != nil {
if _, err = notify.InitFCMClient(cfg, cfg.Android.APIKey); err != nil {
logx.LogError.Fatal(err)
}
}
if cfg.Huawei.Enabled {
if _, err = gorush.InitHMSClient(cfg, cfg.Huawei.AppSecret, cfg.Huawei.AppID); err != nil {
if _, err = notify.InitHMSClient(cfg, cfg.Huawei.AppSecret, cfg.Huawei.AppID); err != nil {
logx.LogError.Fatal(err)
}
}
@ -399,7 +399,7 @@ func main() {
}
}
// Version control for gorush.
// Version control for notify.
var Version = "No Version Provided"
var usageStr = `

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"bytes"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"log"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"github.com/appleboy/go-fcm"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"log"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"errors"
@ -8,12 +8,12 @@ import (
"strings"
"sync"
"github.com/appleboy/go-fcm"
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/queue"
"github.com/appleboy/go-fcm"
jsoniter "github.com/json-iterator/go"
"github.com/msalihkarakasli/go-hms-push/push/model"
)

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"crypto/ecdsa"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"log"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"errors"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"os"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"context"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"testing"

View File

@ -1,4 +1,4 @@
package gorush
package notify
import (
"testing"

View File

@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
"github.com/nsqio/go-nsq"
@ -77,11 +77,11 @@ func NewWorker(opts ...Option) *Worker {
// In this case, a message with an empty body is simply ignored/discarded.
return nil
}
var notification *gorush.PushNotification
var notification *notify.PushNotification
if err := json.Unmarshal(msg.Body, &notification); err != nil {
return err
}
gorush.SendNotification(notification)
notify.SendNotification(notification)
return nil
},
}

View File

@ -4,7 +4,7 @@ import (
"errors"
"runtime"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
)
@ -84,7 +84,7 @@ func NewWorker(opts ...Option) *Worker {
w := &Worker{
queueNotification: make(chan queue.QueuedMessage, runtime.NumCPU()<<1),
runFunc: func(msg queue.QueuedMessage) error {
gorush.SendNotification(msg)
notify.SendNotification(msg)
return nil
},
}

View File

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
"github.com/stretchr/testify/assert"
@ -29,7 +29,7 @@ func TestQueueUsage(t *testing.T) {
assert.Equal(t, runtime.NumCPU()<<1, w.Capacity())
assert.Equal(t, 0, w.Usage())
w.Queue(&gorush.PushNotification{})
w.Queue(&notify.PushNotification{})
assert.Equal(t, 1, w.Usage())
}
@ -38,14 +38,14 @@ func TestMaxCapacity(t *testing.T) {
assert.Equal(t, 2, w.Capacity())
assert.Equal(t, 0, w.Usage())
assert.NoError(t, w.Queue(&gorush.PushNotification{}))
assert.NoError(t, w.Queue(&notify.PushNotification{}))
assert.Equal(t, 1, w.Usage())
assert.NoError(t, w.Queue(&gorush.PushNotification{}))
assert.NoError(t, w.Queue(&notify.PushNotification{}))
assert.Equal(t, 2, w.Usage())
assert.Error(t, w.Queue(&gorush.PushNotification{}))
assert.Error(t, w.Queue(&notify.PushNotification{}))
assert.Equal(t, 2, w.Usage())
err := w.Queue(&gorush.PushNotification{})
err := w.Queue(&notify.PushNotification{})
assert.Equal(t, errMaxCapacity, err)
}

View File

@ -11,9 +11,9 @@ import (
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/metric"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
"github.com/appleboy/gorush/status"
@ -65,7 +65,7 @@ func versionHandler(c *gin.Context) {
func pushHandler(cfg config.ConfYaml, q *queue.Queue) gin.HandlerFunc {
return func(c *gin.Context) {
var form gorush.RequestPush
var form notify.RequestPush
var msg string
if err := c.ShouldBindWith(&form, binding.JSON); err != nil {
@ -228,7 +228,7 @@ func routerEngine(cfg config.ConfYaml, q *queue.Queue) *gin.Engine {
}
// markFailedNotification adds failure logs for all tokens in push notification
func markFailedNotification(cfg config.ConfYaml, notification *gorush.PushNotification, reason string) {
func markFailedNotification(cfg config.ConfYaml, notification *notify.PushNotification, reason string) {
logx.LogError.Error(reason)
for _, token := range notification.Tokens {
notification.AddLog(logx.GetLogPushEntry(&logx.InputLog{
@ -246,10 +246,10 @@ func markFailedNotification(cfg config.ConfYaml, notification *gorush.PushNotifi
}
// HandleNotification add notification to queue list.
func handleNotification(ctx context.Context, cfg config.ConfYaml, req gorush.RequestPush, q *queue.Queue) (int, []logx.LogPushEntry) {
func handleNotification(ctx context.Context, cfg config.ConfYaml, req notify.RequestPush, q *queue.Queue) (int, []logx.LogPushEntry) {
var count int
wg := sync.WaitGroup{}
newNotification := []*gorush.PushNotification{}
newNotification := []*notify.PushNotification{}
if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) {
cfg.Core.Sync = false

View File

@ -13,7 +13,7 @@ import (
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/queue"
"github.com/appleboy/gorush/queue/simple"
"github.com/appleboy/gorush/status"
@ -291,7 +291,7 @@ func TestEmptyNotifications(t *testing.T) {
// notifications is empty.
r.POST("/api/push").
SetJSON(gofight.D{
"notifications": []gorush.PushNotification{},
"notifications": []notify.PushNotification{},
}).
Run(routerEngine(cfg, q), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusBadRequest, r.Code)
@ -322,7 +322,7 @@ func TestMutableContent(t *testing.T) {
},
}).
Run(routerEngine(cfg, q), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
// json: cannot unmarshal number into Go struct field gorush.PushNotification.mutable_content of type bool
// json: cannot unmarshal number into Go struct field notify.PushNotification.mutable_content of type bool
assert.Equal(t, http.StatusBadRequest, r.Code)
})
}
@ -457,7 +457,7 @@ func TestSenMultipleNotifications(t *testing.T) {
cfg.Ios.Enabled = true
cfg.Ios.KeyPath = "../certificate/certificate-valid.pem"
err := gorush.InitAPNSClient(cfg)
err := notify.InitAPNSClient(cfg)
assert.Nil(t, err)
cfg.Android.Enabled = true
@ -465,8 +465,8 @@ func TestSenMultipleNotifications(t *testing.T) {
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// ios
{
Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"},
@ -493,7 +493,7 @@ func TestDisabledAndroidNotifications(t *testing.T) {
cfg.Ios.Enabled = true
cfg.Ios.KeyPath = "../certificate/certificate-valid.pem"
err := gorush.InitAPNSClient(cfg)
err := notify.InitAPNSClient(cfg)
assert.Nil(t, err)
cfg.Android.Enabled = false
@ -501,8 +501,8 @@ func TestDisabledAndroidNotifications(t *testing.T) {
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// ios
{
Tokens: []string{"11aa01229f15f0f0c5209d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"},
@ -529,7 +529,7 @@ func TestSyncModeForNotifications(t *testing.T) {
cfg.Ios.Enabled = true
cfg.Ios.KeyPath = "../certificate/certificate-valid.pem"
err := gorush.InitAPNSClient(cfg)
err := notify.InitAPNSClient(cfg)
assert.Nil(t, err)
cfg.Android.Enabled = true
@ -540,8 +540,8 @@ func TestSyncModeForNotifications(t *testing.T) {
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// ios
{
Tokens: []string{
@ -575,8 +575,8 @@ func TestSyncModeForTopicNotification(t *testing.T) {
// enable sync mode
cfg.Core.Sync = true
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// android
{
// error:InvalidParameters
@ -619,8 +619,8 @@ func TestSyncModeForDeviceGroupNotification(t *testing.T) {
// enable sync mode
cfg.Core.Sync = true
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// android
{
To: "aUniqueKey",
@ -641,7 +641,7 @@ func TestDisabledIosNotifications(t *testing.T) {
cfg.Ios.Enabled = false
cfg.Ios.KeyPath = "../certificate/certificate-valid.pem"
err := gorush.InitAPNSClient(cfg)
err := notify.InitAPNSClient(cfg)
assert.Nil(t, err)
cfg.Android.Enabled = true
@ -649,8 +649,8 @@ func TestDisabledIosNotifications(t *testing.T) {
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
req := gorush.RequestPush{
Notifications: []gorush.PushNotification{
req := notify.RequestPush{
Notifications: []notify.PushNotification{
// ios
{
Tokens: []string{"11aa01229f15f0f0c52021d8cf3cd0ae1f2365fe4cebc4af26cd6d76b7919ef7"},

View File

@ -8,8 +8,8 @@ import (
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/notify"
"github.com/appleboy/gorush/rpc/proto"
"google.golang.org/grpc"
@ -55,7 +55,7 @@ func (s *Server) Check(ctx context.Context, in *proto.HealthCheckRequest) (*prot
// Send implements helloworld.GreeterServer
func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*proto.NotificationReply, error) {
badge := int(in.Badge)
notification := gorush.PushNotification{
notification := notify.PushNotification{
Cfg: s.cfg,
Platform: int(in.Platform),
Tokens: in.Tokens,
@ -81,7 +81,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
}
if in.Alert != nil {
notification.Alert = gorush.Alert{
notification.Alert = notify.Alert{
Title: in.Alert.Title,
Body: in.Alert.Body,
Subtitle: in.Alert.Subtitle,
@ -102,7 +102,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
}
}
go gorush.SendNotification(&notification)
go notify.SendNotification(&notification)
return &proto.NotificationReply{
Success: true,