mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: 消息模块重构,infra包路径简写等
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package msgx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
)
|
||||
|
||||
type MsgType int8
|
||||
@@ -15,6 +16,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
ChannelTypeSiteMsg ChannelType = "siteMsg" // 站内消息
|
||||
ChannelTypeWs ChannelType = "ws" // websocket
|
||||
ChannelTypeEmail ChannelType = "email"
|
||||
ChannelTypeDingBot ChannelType = "dingBot"
|
||||
ChannelTypeQywxBot ChannelType = "qywxBot"
|
||||
@@ -26,35 +29,35 @@ const (
|
||||
)
|
||||
|
||||
// Send 发送消息
|
||||
func Send(channel *Channel, msg *Msg) error {
|
||||
func Send(ctx context.Context, channel *Channel, msg *Msg) error {
|
||||
sender, err := GetMsgSender(channel.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sender.Send(channel, msg)
|
||||
return sender.Send(ctx, channel, msg)
|
||||
}
|
||||
|
||||
type Receiver struct {
|
||||
model.ExtraData
|
||||
Extra collx.M
|
||||
|
||||
Id uint64 // 接收人ID
|
||||
Mobile string
|
||||
Email string
|
||||
}
|
||||
|
||||
type Msg struct {
|
||||
model.ExtraData
|
||||
|
||||
Title string // 消息title
|
||||
Type MsgType // 消息类型
|
||||
Content string // 消息内容
|
||||
Params map[string]any // 消息参数(替换消息中的占位符)
|
||||
Title string // 消息title
|
||||
Type MsgType // 消息类型
|
||||
Content string // 模板消息内容
|
||||
Params map[string]any // 消息参数(替换消息中的占位符)
|
||||
TmplExtra collx.M // 模板消息额外信息
|
||||
|
||||
Receivers []Receiver // 消息接收人
|
||||
}
|
||||
|
||||
// Channel 消息发送渠道信息
|
||||
type Channel struct {
|
||||
model.ExtraData
|
||||
Extra collx.M
|
||||
|
||||
Type ChannelType // 渠道类型
|
||||
Name string
|
||||
@@ -64,7 +67,7 @@ type Channel struct {
|
||||
// MsgSender 定义消息发送接口
|
||||
type MsgSender interface {
|
||||
// Send 发送消息
|
||||
Send(channel *Channel, msg *Msg) error
|
||||
Send(ctx context.Context, channel *Channel, msg *Msg) error
|
||||
}
|
||||
|
||||
var messageSenders = make(map[ChannelType]MsgSender)
|
||||
|
||||
Reference in New Issue
Block a user