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

gogo get github.com/gorilla/websocket

Methods

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.

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.