fasthttp / websocket

WebSocket implementation for fasthttp.
BSD 2-Clause "Simplified" License
540 stars 55 forks source link

Other upgraders? #14

Closed betim closed 5 years ago

betim commented 5 years ago

How do we upgrade a *fasthttp.RequestCtx??

savsgio commented 5 years ago

For upgrade connection:

var upgrader = websocket.FastHTTPUpgrader{}

func example(ctx *fasthttp.RequestCtx) {
    err := upgrader.Upgrade(ctx, func(ws *websocket.Conn) {
        defer ws.Close()
        // .... your code
    })

    if err != nil {
        if _, ok := err.(websocket.HandshakeError); ok {
            log.Println(err)
        }
        return
    }
}
betim commented 5 years ago

Thanks for this. I could not find an example that explained it clearly and I think there should be one.

savsgio commented 5 years ago

You could check examples directory, that in each example have a fasthttp directory to see how to use it