修改infra除repository包

This commit is contained in:
2025-11-05 22:22:46 +08:00
parent 07d8c719ac
commit 97aea66f7c
13 changed files with 293 additions and 242 deletions

View File

@@ -1,6 +1,7 @@
package notify
import (
"context"
"fmt"
"net/smtp"
"strings"
@@ -8,6 +9,7 @@ import (
// smtpNotifier 实现了 Notifier 接口,用于通过 SMTP 发送邮件通知。
type smtpNotifier struct {
ctx context.Context
host string // SMTP 服务器地址
port int // SMTP 服务器端口
username string // 发件人邮箱地址
@@ -17,8 +19,9 @@ type smtpNotifier struct {
// NewSMTPNotifier 创建一个新的 smtpNotifier 实例。
// 调用者需要注入 SMTP 相关的配置。
func NewSMTPNotifier(host string, port int, username, password, sender string) Notifier {
func NewSMTPNotifier(ctx context.Context, host string, port int, username, password, sender string) Notifier {
return &smtpNotifier{
ctx: ctx,
host: host,
port: port,
username: username,
@@ -28,7 +31,7 @@ func NewSMTPNotifier(host string, port int, username, password, sender string) N
}
// Send 使用 net/smtp 包发送一封邮件。
func (s *smtpNotifier) Send(content AlarmContent, toAddr string) error {
func (s *smtpNotifier) Send(ctx context.Context, content AlarmContent, toAddr string) error {
// 1. 设置认证信息
auth := smtp.PlainAuth("", s.username, s.password, s.host)