modulepackage
0.0.0-20241029104240-8ecaae2ad215
Repository: https://github.com/lixiang4u/go-websocket.git
Documentation: pkg.go.dev
# README
demo启动方式
go run _examples/main.go
使用方式
说明
- 基于
github.com/gorilla/websocket
包
导入包
go get github.com/lixiang4u/go-websocket
实例化对象
import (
go_websocket "github.com/lixiang4u/go-websocket"
)
var ws = go_websocket.NewWebsocketManager()
注册响应事件
- 内置事件返回true才会执行自定义事件,否则直接执行自定义事件
ws.On(eventName string, f eventHandler)
- 需要客户端请求数据格式为
protocol
对象的json字面量
type EventProtocol struct {
Event string `json:"event"`
Data interface{} `json:"data"`
}
- 内置事件如下(部分事件不直接对外暴露):
"connect",
"sendToUid",
"listGroup",
"listGroupClient",
"joinGroup",
"leaveGroup",
"close",
"ping",
"bindUid",
"sendToClient",
"sendToGroup"
运行
ws.Handler(w http.ResponseWriter, r *http.Request, responseHeader http.Header)
广播聊天截图
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
EventProtocol ws数据交互格式,基于json,event字段必选.
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
EventHandler 事件响应格式.
No description provided by the author