Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
ClientConn WebSocket 客户端连接
func NewClient ¶
func NewClient(url, protocol, origin string) (*ClientConn, error)
NewClient 创建 WebSocket 客户端连接
func (*ClientConn) Read ¶
func (c *ClientConn) Read(v []byte) (n int, err error)
Read 读取数据(实现 io.Reader 接口,流式读取)
func (*ClientConn) Write ¶
func (c *ClientConn) Write(p []byte) (n int, err error)
Write 写入数据(实现 io.Writer 接口,流式写入)
type Message ¶
type Message struct {
Method string `json:"method"`
TaskID uint `json:"taskId"`
Success bool `json:"success"`
Message string `json:"message"`
Payload any `json:"payload"`
}
Message WebSocket 消息结构
type ServerConfig ¶
type ServerConfig struct {
AllowedOrigins []string // 允许的 Origin 列表,支持通配符 *
}
ServerConfig WebSocket 服务端配置
func (*ServerConfig) CheckOrigin ¶
func (c *ServerConfig) CheckOrigin(origin string) bool
CheckOrigin 检查 Origin 是否允许
func (*ServerConfig) CorsMiddleware ¶
func (c *ServerConfig) CorsMiddleware() gin.HandlerFunc
CorsMiddleware CORS 中间件
func (*ServerConfig) Handler ¶
func (c *ServerConfig) Handler(handler func(*ServerConn)) gin.HandlerFunc
Handler 创建 WebSocket 处理器(gin HandlerFunc) 使用方式:router.GET("/ws", config.Handler(func(conn *ServerConn) { ... }))
Source Files
¶
- client.go
- message.go
- server.go
Click to show internal directories.
Click to hide internal directories.