43 lines
		
	
	
		
			970 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			970 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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
 | |
| }
 |