- 基于
github.com/gorilla/websocket
包 - 增加了
client_id
,区分客户端 - 可以发送消息到指定
client_id
go get github.com/lixiang4u/go-websocket
var ws = go_websocket.WSWrapper{}
ws.On(eventName string, f eventHandler)
- 需要客户端请求数据格式为
protocol
对象的json字面量
type protocol struct {
Event string `json:"event"`
Data interface{} `json:"data"`
}
- 测试返回的数据格式为
protocol
对象的json字面量
type protocol struct {
ClientId string `json:"client_id"`
Event string `json:"event"`
Data interface{} `json:"data"`
}
ws.Run(w http.ResponseWriter, r *http.Request, responseHeader http.Header)