notification

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package notification HTTP 处理器

Package notification 通知模块模型

Package notification 通知模块

Package notification 通知服务

Package notification WebSocket Hub

Index

Constants

This section is empty.

Variables

AllCategories 所有类别

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 Category

type Category string

Category 通知类别

const (
	CategorySystem   Category = "system"   // 系统通知
	CategorySecurity Category = "security" // 安全警报
	CategoryStorage  Category = "storage"  // 存储警告
	CategoryBackup   Category = "backup"   // 备份通知
	CategoryApp      Category = "app"      // 应用通知
	CategoryUpdate   Category = "update"   // 更新提醒
)

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

type DingTalkConfig struct {
	WebhookURL string `json:"webhook_url"`
	Secret     string `json:"secret"`
}

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

func (h *Handler) CreateChannel(c *gin.Context)

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

func (h *Handler) CreateRule(c *gin.Context)

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

func (h *Handler) DeleteAllNotifications(c *gin.Context)

DeleteAllNotifications 删除所有通知 @Summary 删除所有通知 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications [delete]

func (*Handler) DeleteChannel

func (h *Handler) DeleteChannel(c *gin.Context)

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

func (h *Handler) DeleteNotification(c *gin.Context)

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

func (h *Handler) DeleteReadNotifications(c *gin.Context)

DeleteReadNotifications 删除已读通知 @Summary 删除已读通知 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications/read [delete]

func (*Handler) DeleteRule

func (h *Handler) DeleteRule(c *gin.Context)

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

func (h *Handler) GetChannel(c *gin.Context)

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

func (h *Handler) GetHistory(c *gin.Context)

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

func (h *Handler) GetRule(c *gin.Context)

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

func (h *Handler) GetSettings(c *gin.Context)

GetSettings 获取通知设置 @Summary 获取通知设置 @Tags notifications @Produce json @Success 200 {object} SettingsResponse @Router /api/v1/notifications/settings [get]

func (*Handler) GetUnreadCount

func (h *Handler) GetUnreadCount(c *gin.Context)

GetUnreadCount 获取未读数量 @Summary 获取未读数量 @Tags notifications @Produce json @Success 200 {object} UnreadCountResponse @Router /api/v1/notifications/unread-count [get]

func (*Handler) ListChannels

func (h *Handler) ListChannels(c *gin.Context)

ListChannels 列出渠道 @Summary 列出所有通知渠道 @Tags notifications @Produce json @Success 200 {array} NotificationChannel @Router /api/v1/notifications/channels [get]

func (*Handler) ListNotifications

func (h *Handler) ListNotifications(c *gin.Context)

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

func (h *Handler) ListRules(c *gin.Context)

ListRules 列出规则 @Summary 列出所有通知规则 @Tags notifications @Produce json @Success 200 {array} NotificationRule @Router /api/v1/notifications/rules [get]

func (*Handler) MarkAllAsRead

func (h *Handler) MarkAllAsRead(c *gin.Context)

MarkAllAsRead 全部标记已读 @Summary 标记所有通知为已读 @Tags notifications @Produce json @Success 200 {object} response @Router /api/v1/notifications/read-all [put]

func (*Handler) MarkAsRead

func (h *Handler) MarkAsRead(c *gin.Context)

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

func (h *Handler) TestChannel(c *gin.Context)

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

func (h *Handler) UpdateChannel(c *gin.Context)

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

func (h *Handler) UpdateRule(c *gin.Context)

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

func (h *Handler) UpdateSettings(c *gin.Context)

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

func (h *Handler) WebSocketHandler(c *gin.Context)

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 New

func New() *Module

New 创建模块实例

func NewModule

func NewModule() *Module

NewModule 创建通知模块(别名)

func (*Module) Dependencies

func (m *Module) Dependencies() []string

Dependencies 返回依赖的模块

func (*Module) GetService

func (m *Module) GetService() *Service

GetService 获取服务实例

func (*Module) ID

func (m *Module) ID() string

ID 返回模块唯一标识

func (*Module) Init

func (m *Module) Init(ctx *module.Context) error

Init 初始化模块

func (*Module) Name

func (m *Module) Name() string

Name 返回模块名称

func (*Module) RegisterRoutes

func (m *Module) RegisterRoutes(router *gin.RouterGroup)

RegisterRoutes 注册路由

func (*Module) SendNotification

func (m *Module) SendNotification(userID string, category Category, severity Severity, title, content, link, source string) error

SendNotification 发送通知(供其他模块调用)

func (*Module) Start

func (m *Module) Start() error

Start 启动模块

func (*Module) Stop

func (m *Module) Stop() error

Stop 停止模块

func (*Module) Version

func (m *Module) Version() string

Version 返回模块版本

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 站内通知

func (Notification) TableName

func (Notification) TableName() string

TableName 表名

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 推送渠道

func (NotificationChannel) TableName

func (NotificationChannel) TableName() string

TableName 表名

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 推送历史

func (NotificationHistory) TableName

func (NotificationHistory) TableName() string

TableName 表名

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 推送规则

func (NotificationRule) TableName

func (NotificationRule) TableName() string

TableName 表名

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 通知设置

func (NotificationSettings) TableName

func (NotificationSettings) TableName() string

TableName 表名

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 NewService

func NewService(db *gorm.DB, logger *zap.Logger) *Service

NewService 创建通知服务

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

func (s *Service) DeleteAllNotifications(ctx context.Context, userID string) error

DeleteAllNotifications 删除所有通知

func (*Service) DeleteChannel

func (s *Service) DeleteChannel(ctx context.Context, id string) error

DeleteChannel 删除渠道

func (*Service) DeleteNotification

func (s *Service) DeleteNotification(ctx context.Context, userID, id string) error

DeleteNotification 删除通知

func (*Service) DeleteReadNotifications

func (s *Service) DeleteReadNotifications(ctx context.Context, userID string) error

DeleteReadNotifications 删除已读通知

func (*Service) DeleteRule

func (s *Service) DeleteRule(ctx context.Context, id string) error

DeleteRule 删除规则

func (*Service) GetChannel

func (s *Service) GetChannel(ctx context.Context, id string) (*NotificationChannel, error)

GetChannel 获取渠道

func (*Service) GetHistory

func (s *Service) GetHistory(ctx context.Context, page, pageSize int) ([]*NotificationHistory, int64, error)

GetHistory 获取推送历史

func (*Service) GetHub

func (s *Service) GetHub() *WebSocketHub

GetHub 获取 WebSocket Hub

func (*Service) GetRule

func (s *Service) GetRule(ctx context.Context, id string) (*NotificationRule, error)

GetRule 获取规则

func (*Service) GetSettings

func (s *Service) GetSettings(ctx context.Context, userID string) (*SettingsResponse, error)

GetSettings 获取通知设置

func (*Service) GetUnreadCount

func (s *Service) GetUnreadCount(ctx context.Context, userID string) (int64, error)

GetUnreadCount 获取未读数量

func (*Service) ListChannels

func (s *Service) ListChannels(ctx context.Context, userID string) ([]*NotificationChannel, error)

ListChannels 列出渠道

func (*Service) ListNotifications

func (s *Service) ListNotifications(ctx context.Context, userID string, req *ListNotificationsRequest) (*NotificationListResponse, error)

ListNotifications 获取通知列表

func (*Service) ListRules

func (s *Service) ListRules(ctx context.Context, userID string) ([]*NotificationRule, error)

ListRules 列出规则

func (*Service) MarkAllAsRead

func (s *Service) MarkAllAsRead(ctx context.Context, userID string) error

MarkAllAsRead 全部标记已读

func (*Service) MarkAsRead

func (s *Service) MarkAsRead(ctx context.Context, userID, id string) error

MarkAsRead 标记为已读

func (*Service) Migrate

func (s *Service) Migrate() error

Migrate 迁移数据库

func (*Service) SendNotification

func (s *Service) SendNotification(ctx context.Context, req *SendNotificationRequest) (*Notification, error)

SendNotification 发送站内通知

func (*Service) SetHub

func (s *Service) SetHub(hub *WebSocketHub)

SetHub 设置 WebSocket Hub

func (*Service) TestChannel

func (s *Service) TestChannel(ctx context.Context, id string) error

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 Severity

type Severity string

Severity 严重级别

const (
	SeverityInfo     Severity = "info"     // 信息
	SeverityWarning  Severity = "warning"  // 警告
	SeverityError    Severity = "error"    // 错误
	SeverityCritical Severity = "critical" // 紧急
)

type TelegramConfig

type TelegramConfig struct {
	BotToken string `json:"bot_token"`
	ChatID   string `json:"chat_id"`
}

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 NewWebSocketHub

func NewWebSocketHub() *WebSocketHub

NewWebSocketHub 创建新的 WebSocket Hub

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 消息格式

type WebhookConfig

type WebhookConfig struct {
	URL         string            `json:"url"`
	Method      string            `json:"method"` // POST, GET
	Headers     map[string]string `json:"headers"`
	ContentType string            `json:"content_type"`
	Template    string            `json:"template"`
}

WebhookConfig Webhook 配置

Jump to

Keyboard shortcuts

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