实现飞书/微信/邮件发送通知

This commit is contained in:
2025-10-24 20:33:15 +08:00
parent 47ed819b9d
commit 9d6876684b
6 changed files with 709 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package notify
import (
"time"
"go.uber.org/zap/zapcore"
)
// DefaultTimeFormat 定义了所有通知中统一使用的时间格式。
const DefaultTimeFormat = "2006-01-02 15:04:05"
// NotifierType 定义了通知器的类型。
type NotifierType string
const (
// NotifierTypeSMTP 表示 SMTP 邮件通知器。
NotifierTypeSMTP NotifierType = "邮件"
// NotifierTypeWeChat 表示企业微信通知器。
NotifierTypeWeChat NotifierType = "企业微信"
// NotifierTypeLark 表示飞书通知器。
NotifierTypeLark NotifierType = "飞书"
)
// AlarmContent 定义了通知的内容
type AlarmContent struct {
// 通知标题
Title string
// 通知信息
Message string
// 通知级别
Level zapcore.Level
// 通知时间
Timestamp time.Time
}
// Notifier 定义了通知发送器的接口
type Notifier interface {
// Send 发送通知
Send(content AlarmContent, toAddr string) error
// Type 返回通知器的类型
Type() NotifierType
}