ego008 avatar

支持 fasthttp 三个 websocket 库

🕛 by ego008

支持 fasthttp 的 websocket 库

以上 3 个都fork from https://github.com/gorilla/websocket

fasthttp-contrib/websocket 一个☝️栗子🌰

Go: fasthttp websocket
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 适合用来做微服务

💘 相关文章

评论

共1条关于"支持 fasthttp 三个 websocket 库"的评论

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.5 Processed in 0ms