修改infra除repository包
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user