API Reference
Gorilla WebSocket
A fast, well-tested WebSocket implementation for Go with client and server upgrade support.
Official Documentation ↗CompatibilityThis documentation covers version
v1.5. Check the official docs for the latest API surface.Installation
go
go get github.com/gorilla/websocketMethods
No methods match this filter.
Gorilla WebSocket upgrades HTTP connections and provides message read and write primitives.
Key Features
- Server upgrade and client dial
- Text and binary message support
- Ping/pong and deadlines
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://pkg.go.dev/github.com/gorilla/websocket · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:02.458Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If the CheckOrigin field is nil, then the Upgrader uses a safe default: fail the handshake if the Origin request header is present and the Origin host is not equal to the Host request header. (https://pkg.go.dev/github.com/gorilla/websocket)
- New ("websocket: bad handshake") ErrBadHandshake is returned when the server response to opening handshake is invalid. (https://pkg.go.dev/github.com/gorilla/websocket)
- All other close messages are likely the result of an application or protocol error and are logged to aid debugging. (https://pkg.go.dev/github.com/gorilla/websocket)
FAQ
- Can one connection be used from multiple goroutines?
- No. A Conn allows one concurrent reader and one concurrent writer; clone or serialize writes to avoid corruption.
- How do I keep long-lived connections alive?
- Send periodic pings and set read deadlines; reset the deadline whenever a message or pong arrives.
- How do I check the origin?
- Set Upgrader.CheckOrigin to validate the Origin header, since the default rejects cross-origin upgrades.
Report a problem with this API docOpens a pre-filled issue on GitHub.