Documentation
¶
Overview ¶
Package notify 提供统一通知中心:多渠道(短信/邮件/站内信等)发送抽象。 业务只依赖统一入口,渠道通过 Register 插拔;与 framework/sms、framework/mail 组合使用。
Index ¶
- type Content
- type MailAdapter
- type Manager
- func (m *Manager) Channels() []string
- func (m *Manager) Register(sender Sender) error
- func (m *Manager) Send(ctx context.Context, channel, target string, content Content) error
- func (m *Manager) SendAll(ctx context.Context, target string, content Content, channels ...string) error
- func (m *Manager) Sender(channel string) (Sender, bool)
- type SMSAdapter
- type Sender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
Title string // 标题(邮件/站内信)
Body string // 正文内容
Template string // 渠道模板 ID
Params map[string]string // 模板参数
}
Content 是通知内容。 Template 为渠道模板 ID(如短信签名模板、邮件模板),Body 为直接内容。 两者至少提供一个;实现按渠道能力选择模板渲染或直发。
type MailAdapter ¶ added in v1.69.0
type MailAdapter struct {
// contains filtered or unexported fields
}
MailAdapter 把 framework/mail 客户端包装为 notify.Sender(渠道 "email")。 content.Title 为邮件主题,content.Body 为 HTML 正文。
func NewMailAdapter ¶ added in v1.69.0
func NewMailAdapter(client *mail.Client) *MailAdapter
NewMailAdapter 创建邮件适配器。
func (*MailAdapter) Channel ¶ added in v1.69.0
func (a *MailAdapter) Channel() string
Channel 返回渠道标识。
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 是多渠道通知管理器。
type SMSAdapter ¶ added in v1.69.0
type SMSAdapter struct {
// contains filtered or unexported fields
}
SMSAdapter 把 framework/sms 客户端包装为 notify.Sender(渠道 "sms")。 content.Template 覆盖默认模板 Code;content.Params 作为模板变量。
func NewSMSAdapter ¶ added in v1.69.0
func NewSMSAdapter(client *sms.Client, signName, templateCode string) *SMSAdapter
NewSMSAdapter 创建短信适配器。 signName/templateCode 为默认值,单次发送可通过 content.Template 覆盖模板。
Click to show internal directories.
Click to hide internal directories.