修改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,26 +1,29 @@
package notify
import (
"context"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
)
// logNotifier 实现了 Notifier 接口,用于将告警信息记录到日志中。
type logNotifier struct {
logger *logs.Logger
ctx context.Context
}
// NewLogNotifier 创建一个新的 logNotifier 实例。
// 它接收一个日志记录器,用于实际的日志输出。
func NewLogNotifier(logger *logs.Logger) Notifier {
func NewLogNotifier(ctx context.Context) Notifier {
return &logNotifier{
logger: logger,
ctx: ctx,
}
}
// Send 将告警内容以结构化的方式记录到日志中。
// toAddr 参数在这里表示告警的预期接收者地址,也会被记录。
func (l *logNotifier) Send(content AlarmContent, toAddr string) error {
l.logger.Infow("告警已记录到日志",
func (l *logNotifier) Send(ctx context.Context, content AlarmContent, toAddr string) error {
logger := logs.TraceLogger(ctx, l.ctx, "Send")
logger.Infow("告警已记录到日志",
"notifierType", NotifierTypeLog,
"title", content.Title,
"message", content.Message,