notify

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicNotificationMessage

type BasicNotificationMessage[T any] interface {
	Message() (T, error)
}

BasicNotificationMessage 是一个泛型接口,Message 可以返回不同类型

type Channel added in v0.1.19

type Channel string

Channel 定义渠道标识

const (
	ChannelFeishu Channel = "feishu"
	ChannelSms    Channel = "sms"
	ChannelEmail  Channel = "email"
	ChannelWechat Channel = "wechat"
)

type GeneratedMessage added in v0.1.5

type GeneratedMessage[T any] struct {
	Data T
}

GeneratedMessage 兼容动态数据

func (*GeneratedMessage[T]) Message added in v0.1.5

func (m *GeneratedMessage[T]) Message() (T, error)

type Handler added in v0.1.19

type Handler interface {
	Send(ctx context.Context, msg *Message) error
}

Handler 定义了统一的发送接口 业务层调用此接口,不关心底层的泛型实现

type Manager added in v0.1.19

type Manager struct {
	// contains filtered or unexported fields
}

Manager 统一管理所有的通知 Handler

func NewManager added in v0.1.19

func NewManager() *Manager

func (*Manager) Broadcast added in v0.1.19

func (m *Manager) Broadcast(ctx context.Context, msg *Message) map[Channel]error

Broadcast 广播消息给所有已注册的渠道 (可选功能)

func (*Manager) Get added in v0.1.19

func (m *Manager) Get(ch Channel) (Handler, bool)

Get 获取指定渠道的 Handler

func (*Manager) Register added in v0.1.19

func (m *Manager) Register(ch Channel, h Handler)

Register 注册一个渠道的 Handler

func (*Manager) Send added in v0.1.19

func (m *Manager) Send(ctx context.Context, ch Channel, msg *Message) error

Send 通过指定渠道发送消息

type Message added in v0.1.19

type Message struct {
	// 基础字段
	To      []string    // 接收者列表 (UserID, Phone, Email 等,取决于 Channel)
	Subject string      // 标题 (邮件、飞书富文本等使用)
	Content string      // 内容 (文本内容)
	Type    MessageType // 消息类型

	// 扩展字段
	TemplateID   string         // 模版 ID (如短信、飞书模板消息)
	TemplateVars map[string]any // 模版变量
	Files        []string       // 附件链接
	Extra        map[string]any // 渠道特定的额外参数 (如飞书的 card_id, 交互配置等)
}

Message 是业务层使用的统一消息模型 它屏蔽了底层渠道的差异,提供了最常用的字段

type MessageType added in v0.1.19

type MessageType string

MessageType 定义消息类型

const (
	MsgTypeText     MessageType = "text"
	MsgTypeMarkdown MessageType = "markdown" // 部分渠道支持,不支持的可能降级为 Text
	MsgTypeCard     MessageType = "card"     // 复杂卡片,通常需要 channel 特定的 Extra 数据
)

type Notifier

type Notifier[T any] interface {
	Send(ctx context.Context, message BasicNotificationMessage[T]) (bool, error)
}

Notifier 是一个发送通知的接口,T 是 BasicNotificationMessage 的返回类型

type NotifierWrap added in v0.1.3

type NotifierWrap interface {
	Send(ctx context.Context) (bool, error)
}

func WrapNotifierDynamic added in v0.1.5

func WrapNotifierDynamic[T any](notifier Notifier[T], messageGen func() (
	BasicNotificationMessage[T], error)) NotifierWrap

func WrapNotifierStatic added in v0.1.5

func WrapNotifierStatic[T any](notifier Notifier[T], message BasicNotificationMessage[T]) NotifierWrap

WrapNotifierStatic 方法,支持静态和动态消息生成

type NotifierWrapper added in v0.1.3

type NotifierWrapper[T any] struct {
	Notifier   Notifier[T]
	Message    BasicNotificationMessage[T]
	MessageGen func() (BasicNotificationMessage[T], error)
}

func (NotifierWrapper[T]) Send added in v0.1.3

func (w NotifierWrapper[T]) Send(ctx context.Context) (bool, error)

type SystemNotify added in v0.1.3

type SystemNotify struct {
	Notify []NotifierWrap
}

func NewSystemNotify added in v0.1.3

func NewSystemNotify() *SystemNotify

func (*SystemNotify) AddNotify added in v0.1.3

func (n *SystemNotify) AddNotify(notifier NotifierWrap)

Directories

Path Synopsis
sms

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL