Been scouring for a while but couldn't find anything that directly answers this.
Can Go handle WS connections and HTTP connections using the same handler?
In short, I'd like to replicate something like SignalR
Been scouring for a while but couldn't find anything that directly answers this.
Can Go handle WS connections and HTTP connections using the same handler?
In short, I'd like to replicate something like SignalR
Yes, the gorilla/websocket package supports upgrade from HTTP to WebSocket in a request handler. See the example at the beginning of the package documentation. The function handler
is a standard HTTP request handler. The call to upgrader.Upgrade
switches the connection to the WebSocket protocol.
The x/net/websocket package requires a separate handler. There are other reasons why you probably don't want to use the x/net/websocket package.