websocket

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleWebSocket

func HandleWebSocket(hub *Hub) gin.HandlerFunc

HandleWebSocket 处理WebSocket连接请求

Types

type Client

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

Client 表示一个WebSocket连接客户端

type Hub

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

Hub 管理所有活跃的WebSocket连接

func NewHub

func NewHub() *Hub

NewHub 创建一个新的Hub实例

func (*Hub) BroadcastToUser

func (h *Hub) BroadcastToUser(userID uint, msgType string, payload interface{})

BroadcastToUser 向特定用户广播消息

func (*Hub) Run

func (h *Hub) Run()

Run 启动Hub的消息处理循环

type Message

type Message struct {
	UserID  uint        `json:"user_id"`
	Type    string      `json:"type"`
	Payload interface{} `json:"payload"`
}

Message WebSocket消息结构

Jump to

Keyboard shortcuts

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