Documentation
¶
Index ¶
- func Handle(handler Handler) gin.HandlerFunc
- func HandleFunc(fn HandlerFunc) gin.HandlerFunc
- func SetCheckOrigin(fn func(r *http.Request) bool)
- type Connection
- func (c *Connection) Close()
- func (c *Connection) IsClosed() bool
- func (c *Connection) Send(data []byte) error
- func (c *Connection) SendJSON(v any) error
- func (c *Connection) SendText(text string) error
- func (c *Connection) SetReadDeadline(t time.Time) error
- func (c *Connection) SetWriteDeadline(t time.Time) error
- type DefaultHandler
- type Handler
- type HandlerFunc
- type Hub
- type Message
- type MessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetCheckOrigin ¶
SetCheckOrigin 设置 Origin 检查函数
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection WebSocket 连接
func NewConnection ¶
func NewConnection(conn *websocket.Conn) *Connection
NewConnection 创建 WebSocket 连接
func (*Connection) SetReadDeadline ¶
func (c *Connection) SetReadDeadline(t time.Time) error
SetReadDeadline 设置读取超时
func (*Connection) SetWriteDeadline ¶
func (c *Connection) SetWriteDeadline(t time.Time) error
SetWriteDeadline 设置写入超时
type DefaultHandler ¶
type DefaultHandler struct {
OnConnectFunc func(conn *Connection)
OnMessageFunc func(conn *Connection, message []byte)
OnCloseFunc func(conn *Connection)
OnErrorFunc func(conn *Connection, err error)
}
DefaultHandler 默认处理器
func (*DefaultHandler) OnClose ¶
func (h *DefaultHandler) OnClose(conn *Connection)
func (*DefaultHandler) OnConnect ¶
func (h *DefaultHandler) OnConnect(conn *Connection)
func (*DefaultHandler) OnError ¶
func (h *DefaultHandler) OnError(conn *Connection, err error)
func (*DefaultHandler) OnMessage ¶
func (h *DefaultHandler) OnMessage(conn *Connection, message []byte)
type Handler ¶
type Handler interface {
OnConnect(conn *Connection)
OnMessage(conn *Connection, message []byte)
OnClose(conn *Connection)
OnError(conn *Connection, err error)
}
Handler WebSocket 处理器接口
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Content any `json:"content"`
}
Message WebSocket 消息
type MessageType ¶
type MessageType string
MessageType 消息类型
const ( TypeText MessageType = "text" TypeBinary MessageType = "binary" TypePing MessageType = "ping" TypePong MessageType = "pong" TypeClose MessageType = "close" )
Click to show internal directories.
Click to hide internal directories.