支持 fasthttp 三个 websocket 库
支持 fasthttp 的 websocket 库
- https://github.com/fasthttp-contrib/websocket
- https://github.com/leavengood/websocket
- https://github.com/clevergo/websocket fork 上面,去掉了支持net/http 功能,改进了Upgrader
补充最近2021年还活跃的库
以上 3 个都fork from https://github.com/gorilla/websocket
fasthttp-contrib/websocket 一个☝️栗子🌰
import (
"github.com/fasthttp-contrib/websocket"
"github.com/vayala/fasthttp"
)
func chat(c *websocket.Conn) {
// defer c.Close()
// mt, message, err := c.ReadMessage()
// c.WriteMessage(mt, message)
}
var upgrader = websocket.New(chat) // use default options
//var upgrader = websocket.Custom(chat, 1024, 1024) // customized options, read and write buffer sizes (int). Default: 4096
// var upgrader = websocket.New(chat).DontCheckOrigin() // it's useful when you have the websocket server on a different machine
func myChatHandler(ctx *fasthttp.RequestCtx) {
err := upgrader.Upgrade(ctx)// returns only error, executes the handler you defined on the websocket.New before (the 'chat' function)
}
func main() {
fasthttp.ListenAndServe(":8080", myChatHandler)
}
fasthttp https://github.com/valyala/fasthttp 适合用来做微服务
0
See Also
Nearby
- 上一篇 › 发现Go也是挺吃资源的,有点担心会爆炸
- 下一篇 › 这编辑器除了代码块,优酷视频,还支持啥?
不支持http 2.0