Skip to content

Commit d7a0cb5

Browse files
committed
refactor: refactor function signatures and imports in notify and router packages
- Remove the import of `github.com/appleboy/gorush/logx` in `notify/feedback.go` - Add the import of `github.com/appleboy/gorush/logx` in `notify/feedback.go` - Change the signature of the `SendNotification` function in `notify/notification.go` - Change the signature of the `Run` function in `notify/notification.go` - Change the signature of the `handleNotification` function in `router/server.go` - Change the signature of the `TestMain` function in `router/server_test.go` - Change the signature of the `Send` method in `rpc/server.go` Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent d4af7bc commit d7a0cb5

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

notify/feedback.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"bytes"
55
"context"
66
"errors"
7-
"github.com/appleboy/gorush/logx"
87
"net"
98
"net/http"
109
"strings"
1110
"time"
11+
12+
"github.com/appleboy/gorush/logx"
1213
)
1314

1415
var feedbackClient *http.Client

notify/notification.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,16 @@ func CheckPushConf(cfg *config.ConfYaml) error {
235235
return nil
236236
}
237237

238-
// SendNotification send notification
239-
func SendNotification(req qcore.QueuedMessage, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
238+
// SendNotification provide send notification.
239+
func SendNotification(
240+
ctx context.Context,
241+
req qcore.QueuedMessage,
242+
cfg *config.ConfYaml,
243+
) (resp *ResponsePush, err error) {
240244
v, ok := req.(*PushNotification)
241245
if !ok {
242246
if err = json.Unmarshal(req.Bytes(), &v); err != nil {
243-
return
247+
return nil, err
244248
}
245249
}
246250

@@ -262,13 +266,13 @@ func SendNotification(req qcore.QueuedMessage, cfg *config.ConfYaml) (resp *Resp
262266
}
263267
}
264268

265-
return
269+
return resp, err
266270
}
267271

268272
// Run send notification
269273
var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg qcore.QueuedMessage) error {
270274
return func(ctx context.Context, msg qcore.QueuedMessage) error {
271-
_, err := SendNotification(msg, cfg)
275+
_, err := SendNotification(ctx, msg, cfg)
272276
return err
273277
}
274278
}

router/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func handleNotification(
290290
func(msg *notify.PushNotification, cfg *config.ConfYaml) {
291291
if err := q.QueueTask(func(ctx context.Context) error {
292292
defer wg.Done()
293-
resp, err := notify.SendNotification(msg, cfg)
293+
resp, err := notify.SendNotification(ctx, msg, cfg)
294294
if err != nil {
295295
return err
296296
}

router/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestMain(m *testing.M) {
4747
q = queue.NewPool(
4848
int(cfg.Core.WorkerNum),
4949
queue.WithFn(func(ctx context.Context, msg qcore.QueuedMessage) error {
50-
_, err := notify.SendNotification(msg, cfg)
50+
_, err := notify.SendNotification(ctx, msg, cfg)
5151
return err
5252
}),
5353
queue.WithLogger(logx.QueueLogger()),

rpc/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
108108
}
109109

110110
go func() {
111-
_, err := notify.SendNotification(&notification, s.cfg)
111+
_, err := notify.SendNotification(ctx, &notification, s.cfg)
112112
if err != nil {
113113
logx.LogError.Error(err)
114114
}

0 commit comments

Comments
 (0)