mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-20 19:29:54 +00:00
fix(notify): optimize gotify code and close unreleased resources.
This commit is contained in:
parent
2d198bcef7
commit
626a86dea7
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user