From 626a86dea7c30c5c19fe4cca31d8c74cb68231b7 Mon Sep 17 00:00:00 2001 From: catfishlty Date: Thu, 3 Apr 2025 09:47:19 +0800 Subject: [PATCH] fix(notify): optimize gotify code and close unreleased resources. --- .../pkg/core/notifier/providers/gotify/gotify.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/pkg/core/notifier/providers/gotify/gotify.go b/internal/pkg/core/notifier/providers/gotify/gotify.go index 1ae7af76..ad0c515e 100644 --- a/internal/pkg/core/notifier/providers/gotify/gotify.go +++ b/internal/pkg/core/notifier/providers/gotify/gotify.go @@ -24,13 +24,6 @@ type NotifierConfig struct { Priority int64 `json:"priority"` } -// Message Gotify 消息体 -type Message struct { - Title string `json:"title"` - Message string `json:"message"` - Priority int64 `json:"priority"` -} - type NotifierProvider struct { config *NotifierConfig logger *slog.Logger @@ -62,7 +55,11 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier { func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) { // Gotify 原生实现, notify 库没有实现, 等待合并 - reqBody := &Message{ + reqBody := &struct { + Title string `json:"title"` + Message string `json:"message"` + Priority int64 `json:"priority"` + }{ Title: subject, Message: message, Priority: n.config.Priority, @@ -92,6 +89,7 @@ func (n *NotifierProvider) Notify(ctx context.Context, subject string, message s if err != nil { return nil, errors.Wrapf(err, "send request to gotify server") } + defer resp.Body.Close() // Read response and verify success result, err := io.ReadAll(resp.Body)