Skip to content

Commit 2aa0557

Browse files
committed
use pointer struct, remove goroutine
1 parent 277dbe1 commit 2aa0557

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/logging/logging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99

10-
func Init(level string, notifyClient NotificationClient) {
10+
func Init(level string, notifyClient *NotificationClient) {
1111
baseHandler := slog.NewTextHandler( os.Stdout, &slog.HandlerOptions{
1212
Level: getLogLevel(level),
1313
AddSource: true,

src/logging/notify.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type NotificationClient struct {
2323
Cfg config.NotifyConfig
2424
}
2525

26-
func InitNotify(cfg config.NotifyConfig) NotificationClient {
27-
return NotificationClient{
26+
func InitNotify(cfg config.NotifyConfig) *NotificationClient {
27+
return &NotificationClient{
2828
Cfg: cfg,
2929
}
3030
}
@@ -123,7 +123,7 @@ func formatRecordJSON(n Notification) string {
123123
}
124124

125125

126-
func (c NotificationClient) SendNotification(n Notification) {
126+
func (c *NotificationClient) SendNotification(n Notification) {
127127
var err error
128128
switch c.Cfg.Service {
129129
case "matrix":

src/logging/notify_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package logging
22

33
import (
4-
"log/slog"
54
"context"
5+
"log/slog"
66
"time"
77
)
88
// slog handler that checks whether to send notifications
99

1010
type notifyHandler struct {
1111
handler slog.Handler
12-
notify NotificationClient
12+
notify *NotificationClient
1313
}
1414

1515
type Notification struct {
@@ -28,7 +28,7 @@ func (h *notifyHandler) Handle(ctx context.Context, r slog.Record) error {
2828
if shouldNotify(r) {
2929
// send notification in another goroutine
3030
notifyStruct := recordToStruct(r)
31-
go h.notify.SendNotification(notifyStruct)
31+
h.notify.SendNotification(notifyStruct)
3232
}
3333
return h.handler.Handle(ctx, r)
3434
}

0 commit comments

Comments
 (0)