Documentation
¶
Overview ¶
Package notify 提供了一个通用的、可扩展的通知组件。
它定义了统一的 Notifier 和 Driver 接口,支持通过插件机制注册不同的通知驱动(如 Console, Bark, Kook 等)。 该组件支持配置化管理,允许在运行时通过配置文件加载和管理多个通知实例。
Index ¶
- func Drivers() []notify.NotifySenderType
- func Register(name notify.NotifySenderType, driver Driver)
- type Config
- type Driver
- type Manager
- func (m *Manager) Broadcast(ctx context.Context, opts ...Option) map[notify.NotifySenderType]error
- func (m *Manager) Close() error
- func (m *Manager) Get(name notify.NotifySenderType) (NotifierWrapper, bool)
- func (m *Manager) InitDrivers() error
- func (m *Manager) Register(name notify.NotifySenderType, n Notifier)
- func (m *Manager) Send(ctx context.Context, name notify.NotifySenderType, opts ...Option) error
- func (m *Manager) Unregister(name notify.NotifySenderType)
- func (m *Manager) WithNotifier(ctx context.Context, senderType notify.NotifySenderType) NotifierWrapper
- type Message
- type Notifier
- type NotifierConfig
- type NotifierWrapper
- type Option
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(name notify.NotifySenderType, driver Driver)
Register 使通知驱动通过提供的名称可用。 如果使用相同的名称调用两次 Register,或者驱动为 nil,它将引发 panic。
Types ¶
type Config ¶
type Config struct {
Notifiers []NotifierConfig `json:"notifiers" yaml:"notifiers"`
}
Config 保存通知系统的配置
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 管理多个通知器实例,提供统一的消息发送和广播接口。 它负责加载配置、实例化驱动以及管理通知器的生命周期。
func (*Manager) Get ¶
func (m *Manager) Get(name notify.NotifySenderType) (NotifierWrapper, bool)
Get 通过名称获取通知器实例
func (*Manager) Register ¶
func (m *Manager) Register(name notify.NotifySenderType, n Notifier)
Register 注册一个新的通知器实例
func (*Manager) Unregister ¶
func (m *Manager) Unregister(name notify.NotifySenderType)
Unregister 注销一个通知器实例
func (*Manager) WithNotifier ¶
func (m *Manager) WithNotifier(ctx context.Context, senderType notify.NotifySenderType) NotifierWrapper
type Message ¶
type Message struct {
Subject string `json:"subject"`
Content string `json:"content"`
Attachments []string `json:"attachments"`
Extra map[string]interface{} `json:"extra"`
}
Message 定义了通知消息的结构
type Notifier ¶
type Notifier interface {
// Send 发送通知
Send(ctx context.Context, msg *Message) error
// Close 关闭通知器并释放资源
Close() error
}
Notifier 是通知驱动必须实现的接口
type NotifierConfig ¶
type NotifierConfig struct {
Name string `json:"name" yaml:"name"` // 此实例的唯一名称
Driver notify.NotifySenderType `json:"driver" yaml:"driver"` // 驱动名称 (例如 "email", "slack")
Config map[string]interface{} `json:"config" yaml:"config"` // 驱动特定配置
}
NotifierConfig 保存单个通知器实例的配置
type NotifierWrapper ¶
type NotifierWrapper struct {
// contains filtered or unexported fields
}
func NewNotifierWrapper ¶
func NewNotifierWrapper(notifier Notifier) NotifierWrapper
func (NotifierWrapper) Close ¶
func (n NotifierWrapper) Close() error
Click to show internal directories.
Click to hide internal directories.