Documentation
¶
Index ¶
- Constants
- func DefaultPubsuber() *pubsuber
- func Init(cfg config.Config) error
- func NewSubscriber() *subscriber
- func PublishChatMessage(ctx context.Context, data *ChatMessage) error
- func PublishNotifyMessage(ctx context.Context, typ string, data any) error
- func PublishWithPayload(ctx context.Context, channel, typ string, data any) error
- type ChatMessage
- type ChatMessageBody
- type FriendInvite
- type Payload
- type SubscribeHandlerFunc
Constants ¶
View Source
const ( // ChannelChatMessage 推送通道聊天消息 ChannelChatMessage = "chat_message" // ChannelNotify 提送通道推送消息 ChannelNotify = "notify" )
View Source
const ( // PayloadTypeChatMessage 聊天消息 PayloadTypeChatMessage = "chat_message" // PayloadTypeFriendInvite 好友邀请 PayloadTypeFriendInvite = "friend_invite" )
Variables ¶
This section is empty.
Functions ¶
func DefaultPubsuber ¶
func DefaultPubsuber() *pubsuber
func NewSubscriber ¶
func NewSubscriber() *subscriber
func PublishChatMessage ¶
func PublishChatMessage(ctx context.Context, data *ChatMessage) error
PublishChatMessage 发布聊天消息到其他服务器上
func PublishNotifyMessage ¶
PublishNotifyMessage 发布聊天消息到其他服务器上
Types ¶
type ChatMessage ¶
type ChatMessage struct {
// ActionID 行为ID
ActionID string `json:"action_id"`
// ReceiverID 接收人; 可以是用户ID,也可以是房间号
ReceiverID int64 `json:"receiver_id"`
// SessionType 会话类型; 1:私聊, 2:群聊
SessionType int `json:"session_type"`
// Type 消息类型: 1-纯文本,2-图片,3-语音,4-视频, 5-位置
Type int `json:"type"`
// 发送人ID
SenderID int64 `json:"sender_id"`
// MessageID 消息ID
MessageID int64 `json:"message_id"`
// CreatedAt 创建
CreatedAt int64 `json:"created_at"`
// Body 消息体;
Body *ChatMessageBody `json:"body"`
// PublishTargets 推送目标列表
// 为什么增加 PublishTargets 这个参数?
// 因为分布式中,会多个服务实例都订阅到该方法,将导致多个服务实例再去查询数据库,比方说群成员列表等,所以预先加入 PublishTargets .
// 订阅者可以直接从传参拿需要推送的目标 ,能尽量少请求数据库就尽量少请求
PublishTargets []int64 `json:"publish_targets,omitempty"`
}
ChatMessage 订阅传输用的聊天消息结构
func NewChatMessage ¶ added in v1.0.2
func NewChatMessage() *ChatMessage
type ChatMessageBody ¶
type ChatMessageBody struct {
// 文本信息。适用消息类型: 1
Text string `bson:"text,omitempty" json:"text,omitempty"`
// 来源地址。通用字段,适用消息类型: 2,3,4
Src string `bson:"src,omitempty" json:"src,omitempty"`
// 文件格式。适用消息类型: 2,3,4
Format string `bson:"format,omitempty" json:"format,omitempty"`
// 文件大小。适用消息类型: 2,3,4
Size string `bson:"size,omitempty" json:"size,omitempty"`
// 位置信息-经度。 适用消息类型: 5
Longitude string `bson:"longitude,omitempty" json:"longitude,omitempty"`
// 位置信息-纬度。 适用消息类型: 5
Latitude string `bson:"latitude,omitempty" json:"latitude,omitempty"`
// 位置信息-地图缩放级别。 适用消息类型: 5
Scale float64 `bson:"scale,omitempty" json:"scale,omitempty"`
// 位置信息标签。适用消息类型: 5
LocationLabel string `bson:"location_label,omitempty" json:"location_label,omitempty"`
}
ChatMessageBody 消息主体
func NewChatMessageBody ¶ added in v1.0.2
func NewChatMessageBody() *ChatMessageBody
type FriendInvite ¶
type FriendInvite struct {
// ID 邀请ID
ID int64 `json:"id"`
// UserID 用户ID
UserID int64 `json:"user_id"`
// TargetID 目标ID
TargetID int64 `json:"target_id"`
// Status 状态
Status int `json:"type"`
// Note 备注
Note string `json:"note"`
// Reply 回复
Reply string `json:"reply"`
// CreatedAt 创建时间
CreatedAt time.Time `json:"created_at"`
}
FriendInvite 订阅服务传输使用的好友请求结果
type Payload ¶
type Payload struct {
// Channel 通道
Channel string `json:"channel,omitempty"`
// Type 类型
Type string `json:"type"`
// Data 具体数据,这里为什么不使用any,因为设置成any最后还需要映射成原来的struct,比较麻烦
Data string `json:"data"`
}
Payload 推送订阅的有效谁
func (*Payload) MarshalBinary ¶
MarshalBinary 实现 encoding.BinaryMarshaler 接口
func (*Payload) UnmarshalBinary ¶
UnmarshalBinary 实现 encoding.UnmarshalBinary 接口
func (*Payload) UnmarshalData ¶
UnmarshalData 解码data里面的数据
type SubscribeHandlerFunc ¶
SubscribeHandlerFunc 订阅处理方法
Click to show internal directories.
Click to hide internal directories.