Documentation
¶
Overview ¶
Package notification HTTP 处理器
Package notification 通知模块模型 ¶
Package notification 通知模块 ¶
Package notification 通知服务 ¶
Package notification WebSocket Hub
Index ¶
- Variables
- type BarkConfig
- type Category
- type ChannelType
- type ChannelWithStatus
- type CreateChannelRequest
- type CreateRuleRequest
- type DingTalkConfig
- type EmailConfig
- type Handler
- func (h *Handler) CreateChannel(c *gin.Context)
- func (h *Handler) CreateRule(c *gin.Context)
- func (h *Handler) DeleteAllNotifications(c *gin.Context)
- func (h *Handler) DeleteChannel(c *gin.Context)
- func (h *Handler) DeleteNotification(c *gin.Context)
- func (h *Handler) DeleteReadNotifications(c *gin.Context)
- func (h *Handler) DeleteRule(c *gin.Context)
- func (h *Handler) GetChannel(c *gin.Context)
- func (h *Handler) GetHistory(c *gin.Context)
- func (h *Handler) GetRule(c *gin.Context)
- func (h *Handler) GetSettings(c *gin.Context)
- func (h *Handler) GetUnreadCount(c *gin.Context)
- func (h *Handler) ListChannels(c *gin.Context)
- func (h *Handler) ListNotifications(c *gin.Context)
- func (h *Handler) ListRules(c *gin.Context)
- func (h *Handler) MarkAllAsRead(c *gin.Context)
- func (h *Handler) MarkAsRead(c *gin.Context)
- func (h *Handler) RegisterRoutes(group *gin.RouterGroup)
- func (h *Handler) TestChannel(c *gin.Context)
- func (h *Handler) UpdateChannel(c *gin.Context)
- func (h *Handler) UpdateRule(c *gin.Context)
- func (h *Handler) UpdateSettings(c *gin.Context)
- func (h *Handler) WebSocketHandler(c *gin.Context)
- type ListNotificationsRequest
- type Module
- func (m *Module) Dependencies() []string
- func (m *Module) GetService() *Service
- func (m *Module) ID() string
- func (m *Module) Init(ctx *module.Context) error
- func (m *Module) Name() string
- func (m *Module) RegisterRoutes(router *gin.RouterGroup)
- func (m *Module) SendNotification(userID string, category Category, severity Severity, ...) error
- func (m *Module) Start() error
- func (m *Module) Stop() error
- func (m *Module) Version() string
- type Notification
- type NotificationChannel
- type NotificationHistory
- type NotificationListResponse
- type NotificationRule
- type NotificationSettings
- type SendNotificationRequest
- type Service
- func (s *Service) CreateChannel(ctx context.Context, userID string, req *CreateChannelRequest) (*NotificationChannel, error)
- func (s *Service) CreateRule(ctx context.Context, userID string, req *CreateRuleRequest) (*NotificationRule, error)
- func (s *Service) DeleteAllNotifications(ctx context.Context, userID string) error
- func (s *Service) DeleteChannel(ctx context.Context, id string) error
- func (s *Service) DeleteNotification(ctx context.Context, userID, id string) error
- func (s *Service) DeleteReadNotifications(ctx context.Context, userID string) error
- func (s *Service) DeleteRule(ctx context.Context, id string) error
- func (s *Service) GetChannel(ctx context.Context, id string) (*NotificationChannel, error)
- func (s *Service) GetHistory(ctx context.Context, page, pageSize int) ([]*NotificationHistory, int64, error)
- func (s *Service) GetHub() *WebSocketHub
- func (s *Service) GetRule(ctx context.Context, id string) (*NotificationRule, error)
- func (s *Service) GetSettings(ctx context.Context, userID string) (*SettingsResponse, error)
- func (s *Service) GetUnreadCount(ctx context.Context, userID string) (int64, error)
- func (s *Service) ListChannels(ctx context.Context, userID string) ([]*NotificationChannel, error)
- func (s *Service) ListNotifications(ctx context.Context, userID string, req *ListNotificationsRequest) (*NotificationListResponse, error)
- func (s *Service) ListRules(ctx context.Context, userID string) ([]*NotificationRule, error)
- func (s *Service) MarkAllAsRead(ctx context.Context, userID string) error
- func (s *Service) MarkAsRead(ctx context.Context, userID, id string) error
- func (s *Service) Migrate() error
- func (s *Service) SendNotification(ctx context.Context, req *SendNotificationRequest) (*Notification, error)
- func (s *Service) SetHub(hub *WebSocketHub)
- func (s *Service) TestChannel(ctx context.Context, id string) error
- func (s *Service) UpdateChannel(ctx context.Context, id string, req *UpdateChannelRequest) (*NotificationChannel, error)
- func (s *Service) UpdateRule(ctx context.Context, id string, req *UpdateRuleRequest) (*NotificationRule, error)
- func (s *Service) UpdateSettings(ctx context.Context, userID string, req *UpdateSettingsRequest) (*SettingsResponse, error)
- type SettingsResponse
- type Severity
- type TelegramConfig
- type UnreadCountResponse
- type UpdateChannelRequest
- type UpdateRuleRequest
- type UpdateSettingsRequest
- type WeChatConfig
- type WebSocketClient
- type WebSocketHub
- func (h *WebSocketHub) Broadcast(message *WebSocketMessage)
- func (h *WebSocketHub) BroadcastNotification(notification *Notification)
- func (h *WebSocketHub) BroadcastUnreadCount(userID string, count int64)
- func (h *WebSocketHub) HandleWebSocket(w http.ResponseWriter, r *http.Request, userID string)
- func (h *WebSocketHub) SendToUser(userID string, message *WebSocketMessage)
- type WebSocketMessage
- type WebhookConfig
Constants ¶
This section is empty.
Variables ¶
var AllCategories = []Category{ CategorySystem, CategorySecurity, CategoryStorage, CategoryBackup, CategoryApp, CategoryUpdate, }
AllCategories 所有类别
var AllSeverities = []Severity{ SeverityInfo, SeverityWarning, SeverityError, SeverityCritical, }
AllSeverities 所有严重级别
Functions ¶
This section is empty.
Types ¶
type BarkConfig ¶
type BarkConfig struct {
ServerURL string `json:"server_url"`
DeviceKey string `json:"device_key"`
}
BarkConfig Bark 配置
type ChannelType ¶
type ChannelType string
ChannelType 推送渠道类型
const ( ChannelEmail ChannelType = "email" ChannelWebhook ChannelType = "webhook" ChannelTelegram ChannelType = "telegram" ChannelWeChat ChannelType = "wechat" ChannelBark ChannelType = "bark" ChannelDingTalk ChannelType = "dingtalk" )
type ChannelWithStatus ¶
type ChannelWithStatus struct {
NotificationChannel
IsConfigured bool `json:"is_configured"`
}
ChannelWithStatus 渠道及状态
type CreateChannelRequest ¶
type CreateChannelRequest struct {
Name string `json:"name" binding:"required"`
Type ChannelType `json:"type" binding:"required"`
Config interface{} `json:"config" binding:"required"`
Description string `json:"description"`
}
CreateChannelRequest 创建渠道请求
type CreateRuleRequest ¶
type CreateRuleRequest struct {
Name string `json:"name" binding:"required"`
ChannelID string `json:"channel_id" binding:"required"`
Categories []string `json:"categories"`
Severities []string `json:"severities"`
Cooldown int `json:"cooldown"`
}
CreateRuleRequest 创建规则请求
type DingTalkConfig ¶
DingTalkConfig 钉钉配置
type EmailConfig ¶
type EmailConfig struct {
SMTPHost string `json:"smtp_host"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
UseTLS bool `json:"use_tls"`
FromAddress string `json:"from_address"`
FromName string `json:"from_name"`
ToAddresses []string `json:"to_addresses"`
}
EmailConfig 邮件配置
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler HTTP 处理器
func NewHandler ¶
func NewHandler(service *Service, tokenManager *auth.TokenManager) *Handler
NewHandler 创建处理器
func (*Handler) CreateChannel ¶
CreateChannel 创建渠道 @Summary 创建通知渠道 @Tags notifications @Accept json @Produce json @Param request body CreateChannelRequest true "渠道信息" @Success 200 {object} NotificationChannel @Router /api/v1/notifications/channels [post]
func (*Handler) CreateRule ¶
CreateRule 创建规则 @Summary 创建通知规则 @Tags notifications @Accept json @Produce json @Param request body CreateRuleRequest true "规则信息" @Success 200 {object} NotificationRule @Router /api/v1/notifications/rules [post]
func (*Handler) DeleteAllNotifications ¶
DeleteAllNotifications 删除所有通知 @Summary 删除所有通知 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications [delete]
func (*Handler) DeleteChannel ¶
DeleteChannel 删除渠道 @Summary 删除通知渠道 @Tags notifications @Produce json @Param id path string true "渠道ID" @Success 200 {object} response @Router /api/v1/notifications/channels/{id} [delete]
func (*Handler) DeleteNotification ¶
DeleteNotification 删除单条通知 @Summary 删除单条通知 @Tags notifications @Produce json @Param id path string true "通知ID" @Success 200 {object} response @Router /api/v1/notifications/{id} [delete]
func (*Handler) DeleteReadNotifications ¶
DeleteReadNotifications 删除已读通知 @Summary 删除已读通知 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications/read [delete]
func (*Handler) DeleteRule ¶
DeleteRule 删除规则 @Summary 删除通知规则 @Tags notifications @Produce json @Param id path string true "规则ID" @Success 200 {object} response @Router /api/v1/notifications/rules/{id} [delete]
func (*Handler) GetChannel ¶
GetChannel 获取渠道 @Summary 获取通知渠道 @Tags notifications @Produce json @Param id path string true "渠道ID" @Success 200 {object} NotificationChannel @Router /api/v1/notifications/channels/{id} [get]
func (*Handler) GetHistory ¶
GetHistory 获取推送历史 @Summary 获取推送历史 @Tags notifications @Produce json @Param page query int false "页码" @Param page_size query int false "每页数量" @Success 200 {array} NotificationHistory @Router /api/v1/notifications/history [get]
func (*Handler) GetRule ¶
GetRule 获取规则 @Summary 获取通知规则 @Tags notifications @Produce json @Param id path string true "规则ID" @Success 200 {object} NotificationRule @Router /api/v1/notifications/rules/{id} [get]
func (*Handler) GetSettings ¶
GetSettings 获取通知设置 @Summary 获取通知设置 @Tags notifications @Produce json @Success 200 {object} SettingsResponse @Router /api/v1/notifications/settings [get]
func (*Handler) GetUnreadCount ¶
GetUnreadCount 获取未读数量 @Summary 获取未读数量 @Tags notifications @Produce json @Success 200 {object} UnreadCountResponse @Router /api/v1/notifications/unread-count [get]
func (*Handler) ListChannels ¶
ListChannels 列出渠道 @Summary 列出所有通知渠道 @Tags notifications @Produce json @Success 200 {array} NotificationChannel @Router /api/v1/notifications/channels [get]
func (*Handler) ListNotifications ¶
ListNotifications 获取通知列表 @Summary 获取通知列表 @Tags notifications @Accept json @Produce json @Param page query int false "页码" @Param page_size query int false "每页数量" @Param category query string false "类别(逗号分隔)" @Param severity query string false "级别(逗号分隔)" @Param is_read query bool false "是否已读" @Success 200 {object} NotificationListResponse @Router /api/v1/notifications [get]
func (*Handler) ListRules ¶
ListRules 列出规则 @Summary 列出所有通知规则 @Tags notifications @Produce json @Success 200 {array} NotificationRule @Router /api/v1/notifications/rules [get]
func (*Handler) MarkAllAsRead ¶
MarkAllAsRead 全部标记已读 @Summary 标记所有通知为已读 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications/read-all [put]
func (*Handler) MarkAsRead ¶
MarkAsRead 标记为已读 @Summary 标记单条通知为已读 @Tags notifications @Produce json @Param id path string true "通知ID" @Success 200 {object} response @Router /api/v1/notifications/{id}/read [put]
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(group *gin.RouterGroup)
RegisterRoutes 注册路由
func (*Handler) TestChannel ¶
TestChannel 测试渠道 @Summary 测试通知渠道 @Tags notifications @Produce json @Param id path string true "渠道ID" @Success 200 {object} response @Router /api/v1/notifications/channels/{id}/test [post]
func (*Handler) UpdateChannel ¶
UpdateChannel 更新渠道 @Summary 更新通知渠道 @Tags notifications @Accept json @Produce json @Param id path string true "渠道ID" @Param request body UpdateChannelRequest true "更新信息" @Success 200 {object} NotificationChannel @Router /api/v1/notifications/channels/{id} [put]
func (*Handler) UpdateRule ¶
UpdateRule 更新规则 @Summary 更新通知规则 @Tags notifications @Accept json @Produce json @Param id path string true "规则ID" @Param request body UpdateRuleRequest true "更新信息" @Success 200 {object} NotificationRule @Router /api/v1/notifications/rules/{id} [put]
func (*Handler) UpdateSettings ¶
UpdateSettings 更新通知设置 @Summary 更新通知设置 @Tags notifications @Accept json @Produce json @Param request body UpdateSettingsRequest true "设置" @Success 200 {object} SettingsResponse @Router /api/v1/notifications/settings [put]
func (*Handler) WebSocketHandler ¶
WebSocketHandler WebSocket 连接处理
type ListNotificationsRequest ¶
type ListNotificationsRequest struct {
Page int `form:"page" json:"page"`
PageSize int `form:"page_size" json:"page_size"`
Category string `form:"category" json:"category"` // 逗号分隔
Severity string `form:"severity" json:"severity"` // 逗号分隔
IsRead *bool `form:"is_read" json:"is_read"`
StartDate string `form:"start_date" json:"start_date"` // 2006-01-02
EndDate string `form:"end_date" json:"end_date"`
}
ListNotificationsRequest 获取通知列表请求
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 通知模块
func (*Module) RegisterRoutes ¶
func (m *Module) RegisterRoutes(router *gin.RouterGroup)
RegisterRoutes 注册路由
type Notification ¶
type Notification struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
UserID string `json:"user_id" gorm:"size:36;index"` // 接收用户(空=全局广播)
Category Category `json:"category" gorm:"size:32;index"` // 类别
Severity Severity `json:"severity" gorm:"size:16;index"` // 严重级别
Title string `json:"title" gorm:"size:255"` // 标题
Content string `json:"content" gorm:"type:text"` // 内容
Link string `json:"link" gorm:"size:512"` // 点击跳转链接
Icon string `json:"icon" gorm:"size:64"` // 图标名称
Source string `json:"source" gorm:"size:64"` // 来源模块
IsRead bool `json:"is_read" gorm:"default:false;index"` // 是否已读
ReadAt *time.Time `json:"read_at"` // 已读时间
CreatedAt time.Time `json:"created_at" gorm:"index"` // 创建时间
ExpiresAt *time.Time `json:"expires_at"` // 过期时间
}
Notification 站内通知
type NotificationChannel ¶
type NotificationChannel struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
UserID string `json:"user_id" gorm:"size:36;index"` // 用户ID(空=系统级)
Name string `json:"name" gorm:"size:64"` // 渠道名称
Type ChannelType `json:"type" gorm:"size:32"` // 渠道类型
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
Config string `json:"config" gorm:"type:text"` // JSON 配置
Description string `json:"description" gorm:"size:255"` // 描述
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
NotificationChannel 推送渠道
type NotificationHistory ¶
type NotificationHistory struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
ChannelID string `json:"channel_id" gorm:"size:36;index"`
ChannelType ChannelType `json:"channel_type" gorm:"size:32"`
Category Category `json:"category" gorm:"size:32"`
Title string `json:"title" gorm:"size:255"`
Content string `json:"content" gorm:"type:text"`
Recipient string `json:"recipient" gorm:"size:255"` // 接收者
Status string `json:"status" gorm:"size:20"` // pending, sent, failed
ErrorMsg string `json:"error_msg" gorm:"type:text"`
SentAt *time.Time `json:"sent_at"`
CreatedAt time.Time `json:"created_at" gorm:"index"`
}
NotificationHistory 推送历史
type NotificationListResponse ¶
type NotificationListResponse struct {
Items []*Notification `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
UnreadCount int64 `json:"unread_count"`
}
NotificationListResponse 通知列表响应
type NotificationRule ¶
type NotificationRule struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
UserID string `json:"user_id" gorm:"size:36;index"` // 用户ID
Name string `json:"name" gorm:"size:64"` // 规则名称
ChannelID string `json:"channel_id" gorm:"size:36"` // 关联渠道
Categories string `json:"categories" gorm:"type:text"` // 触发类别 JSON
Severities string `json:"severities" gorm:"type:text"` // 触发级别 JSON
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
Cooldown int `json:"cooldown" gorm:"default:0"` // 冷却时间(秒)
LastSentAt *time.Time `json:"last_sent_at"` // 上次发送
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
NotificationRule 推送规则
type NotificationSettings ¶
type NotificationSettings struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
UserID string `json:"user_id" gorm:"size:36;uniqueIndex"` // 用户ID
Enabled bool `json:"enabled" gorm:"default:true"` // 启用通知
DesktopNotify bool `json:"desktop_notify" gorm:"default:true"` // 桌面通知
SoundEnabled bool `json:"sound_enabled" gorm:"default:true"` // 提示音
DndEnabled bool `json:"dnd_enabled" gorm:"default:false"` // 免打扰
DndFrom string `json:"dnd_from" gorm:"size:8"` // 免打扰开始 "22:00"
DndTo string `json:"dnd_to" gorm:"size:8"` // 免打扰结束 "08:00"
FilterCategories string `json:"filter_categories" gorm:"type:text"` // 启用的类别 JSON
FilterSeverities string `json:"filter_severities" gorm:"type:text"` // 启用的级别 JSON
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
NotificationSettings 通知设置
type SendNotificationRequest ¶
type SendNotificationRequest struct {
UserID string `json:"user_id"` // 空=广播给所有用户
Category Category `json:"category" binding:"required"`
Severity Severity `json:"severity" binding:"required"`
Title string `json:"title" binding:"required"`
Content string `json:"content" binding:"required"`
Link string `json:"link"`
Source string `json:"source"`
}
SendNotificationRequest 发送通知请求(内部API)
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 通知服务
func (*Service) CreateChannel ¶
func (s *Service) CreateChannel(ctx context.Context, userID string, req *CreateChannelRequest) (*NotificationChannel, error)
CreateChannel 创建渠道
func (*Service) CreateRule ¶
func (s *Service) CreateRule(ctx context.Context, userID string, req *CreateRuleRequest) (*NotificationRule, error)
CreateRule 创建规则
func (*Service) DeleteAllNotifications ¶
DeleteAllNotifications 删除所有通知
func (*Service) DeleteChannel ¶
DeleteChannel 删除渠道
func (*Service) DeleteNotification ¶
DeleteNotification 删除通知
func (*Service) DeleteReadNotifications ¶
DeleteReadNotifications 删除已读通知
func (*Service) DeleteRule ¶
DeleteRule 删除规则
func (*Service) GetChannel ¶
GetChannel 获取渠道
func (*Service) GetHistory ¶
func (s *Service) GetHistory(ctx context.Context, page, pageSize int) ([]*NotificationHistory, int64, error)
GetHistory 获取推送历史
func (*Service) GetSettings ¶
GetSettings 获取通知设置
func (*Service) GetUnreadCount ¶
GetUnreadCount 获取未读数量
func (*Service) ListChannels ¶
ListChannels 列出渠道
func (*Service) ListNotifications ¶
func (s *Service) ListNotifications(ctx context.Context, userID string, req *ListNotificationsRequest) (*NotificationListResponse, error)
ListNotifications 获取通知列表
func (*Service) MarkAllAsRead ¶
MarkAllAsRead 全部标记已读
func (*Service) MarkAsRead ¶
MarkAsRead 标记为已读
func (*Service) SendNotification ¶
func (s *Service) SendNotification(ctx context.Context, req *SendNotificationRequest) (*Notification, error)
SendNotification 发送站内通知
func (*Service) TestChannel ¶
TestChannel 测试渠道
func (*Service) UpdateChannel ¶
func (s *Service) UpdateChannel(ctx context.Context, id string, req *UpdateChannelRequest) (*NotificationChannel, error)
UpdateChannel 更新渠道
func (*Service) UpdateRule ¶
func (s *Service) UpdateRule(ctx context.Context, id string, req *UpdateRuleRequest) (*NotificationRule, error)
UpdateRule 更新规则
func (*Service) UpdateSettings ¶
func (s *Service) UpdateSettings(ctx context.Context, userID string, req *UpdateSettingsRequest) (*SettingsResponse, error)
UpdateSettings 更新通知设置
type SettingsResponse ¶
type SettingsResponse struct {
Enabled bool `json:"enabled"`
DesktopNotify bool `json:"desktop_notify"`
SoundEnabled bool `json:"sound_enabled"`
DndEnabled bool `json:"dnd_enabled"`
DndFrom string `json:"dnd_from"`
DndTo string `json:"dnd_to"`
FilterCategories []string `json:"filter_categories"`
FilterSeverities []string `json:"filter_severities"`
}
SettingsResponse 设置响应
type TelegramConfig ¶
TelegramConfig Telegram 配置
type UnreadCountResponse ¶
type UnreadCountResponse struct {
Count int64 `json:"count"`
}
UnreadCountResponse 未读数量响应
type UpdateChannelRequest ¶
type UpdateChannelRequest struct {
Name string `json:"name"`
Config interface{} `json:"config"`
Description string `json:"description"`
Enabled *bool `json:"enabled"`
}
UpdateChannelRequest 更新渠道请求
type UpdateRuleRequest ¶
type UpdateRuleRequest struct {
Name string `json:"name"`
Categories []string `json:"categories"`
Severities []string `json:"severities"`
Cooldown *int `json:"cooldown"`
Enabled *bool `json:"enabled"`
}
UpdateRuleRequest 更新规则请求
type UpdateSettingsRequest ¶
type UpdateSettingsRequest struct {
Enabled *bool `json:"enabled"`
DesktopNotify *bool `json:"desktop_notify"`
SoundEnabled *bool `json:"sound_enabled"`
DndEnabled *bool `json:"dnd_enabled"`
DndFrom string `json:"dnd_from"`
DndTo string `json:"dnd_to"`
FilterCategories []string `json:"filter_categories"`
FilterSeverities []string `json:"filter_severities"`
}
UpdateSettingsRequest 更新设置请求
type WeChatConfig ¶
type WeChatConfig struct {
WebhookURL string `json:"webhook_url"`
}
WeChatConfig 企业微信配置
type WebSocketClient ¶
type WebSocketClient struct {
// contains filtered or unexported fields
}
WebSocketClient 单个 WebSocket 客户端
type WebSocketHub ¶
type WebSocketHub struct {
// contains filtered or unexported fields
}
WebSocketHub 管理所有 WebSocket 连接
func (*WebSocketHub) Broadcast ¶
func (h *WebSocketHub) Broadcast(message *WebSocketMessage)
Broadcast 广播任意消息给所有连接的客户端
func (*WebSocketHub) BroadcastNotification ¶
func (h *WebSocketHub) BroadcastNotification(notification *Notification)
BroadcastNotification 广播新通知
func (*WebSocketHub) BroadcastUnreadCount ¶
func (h *WebSocketHub) BroadcastUnreadCount(userID string, count int64)
BroadcastUnreadCount 广播未读数量
func (*WebSocketHub) HandleWebSocket ¶
func (h *WebSocketHub) HandleWebSocket(w http.ResponseWriter, r *http.Request, userID string)
HandleWebSocket 处理 WebSocket 连接
func (*WebSocketHub) SendToUser ¶
func (h *WebSocketHub) SendToUser(userID string, message *WebSocketMessage)
SendToUser 发送消息给指定用户
type WebSocketMessage ¶
type WebSocketMessage struct {
Type string `json:"type"` // notification, unread_count
Data interface{} `json:"data"`
}
WebSocketMessage WebSocket 消息格式