websocket

A fast, RFC 6455-compliant WebSocket implementation for Go with full control over framing, compression, and concurrency.

Library
Go
vv1.5.3
24,878 stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
51 /100 Fair
Development Activity 0
Maintenance 20
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 82
Code Quality 85
Innovation 78
Learning Curve 65

Gorilla WebSocket is a Go implementation of the WebSocket protocol (RFC 6455) providing both server-side (Upgrader) and client-side (Dialer) connection types built directly on net/http and net.Conn. Instead of hiding the protocol behind a high-level abstraction, it exposes byte-level control over frame masking, per-message compression, and control-frame (ping/pong/close) handling, while still offering convenience methods like ReadJSON/WriteJSON for the common structured-message case.

The package has near-zero dependencies, passes the Autobahn Test Suite’s protocol-conformance tests, and ships runnable examples for chat servers, remote command execution, echo clients, and file-watch notifications. It is one of the most widely used low-level WebSocket libraries in the Go ecosystem, commonly reached for by projects that need direct control over connection lifecycle and framing rather than a batteries-included realtime framework.

What You Get

  • An Upgrader type for turning an *http.Request into a WebSocket *Conn on the server side, with origin-checking and subprotocol negotiation built in.
  • A Dialer type for opening outbound WebSocket connections as a client, including TLS, proxy, and custom net.Conn dial support.
  • Streaming NextReader/NextWriter APIs plus convenience ReadMessage/WriteMessage/ReadJSON/WriteJSON methods.
  • Optional permessage-deflate compression negotiation with per-connection compression level control.
  • Runnable examples covering chat servers, command execution over WebSockets, echo clients/servers, and file-watch notifications.

Common Use Cases

  • Building chat and messaging backends that need a persistent, bidirectional connection to browser or mobile clients.
  • Streaming live server-side data such as logs, metrics, or prices to a JavaScript frontend without polling.
  • Building custom realtime protocols on top of raw WebSocket frames where a full framework would be overkill.
  • Proxying or relaying WebSocket traffic between a Go client and an upstream WebSocket server.

Under The Hood

Architecture Gorilla WebSocket centers on the *Conn type defined in conn.go, which wraps a net.Conn together with read/write frame buffers, deadlines, and pluggable close/ping/pong handlers; server.go’s Upgrader.Upgrade hijacks an *http.Request/http.ResponseWriter pair (via http.Hijacker) to produce a *Conn after validating the Sec-WebSocket-Key handshake and negotiating subprotocols/origin checks, while client.go’s Dialer.Dial and DialContext perform the mirrored client-side handshake over a net.Conn obtained from netDialFn (with TLS and HTTP/SOCKS proxy support in proxy.go). Frame masking is isolated behind a maskBytes function with two implementations selected by build tag — mask.go’s unsafe, word-aligned XOR loop and mask_safe.go’s byte-at-a-time App Engine-safe fallback — and permessage-deflate compression is factored into compression.go behind pooled flate.Reader/Writer instances so Conn stays framing-agnostic. Changing the core Conn read/write buffering would ripple through every public method (ReadMessage, NextReader, WriteJSON, and others) since they all funnel through the same frame-header parsing state machine.

Tech Stack The library targets a recent Go toolchain and has exactly one external dependency, golang.org/x/net, used only for proxy- and test-related helpers rather than the core protocol code, keeping the module close to a pure standard-library implementation built on net, net/http, crypto/tls, and compress/flate. There is no additional build system beyond the standard Go toolchain; CI runs through CircleCI per the project’s badge, and the bundled examples directory (chat, command, echo, filewatch, autobahn) doubles as integration coverage and demonstrates the library wired directly into net/http handlers with no additional framework involved, since this is a transport-layer library rather than an application framework.

Code Quality The repository carries a large body of test files alongside its implementation files, giving close to one-to-one test-to-source coverage including a dedicated Autobahn protocol-conformance suite run against the reference test client. Error handling is explicit and typed rather than swallowed: sentinel errors and a dedicated CloseError/HandshakeError pair carry protocol-level detail back to callers instead of generic error strings everywhere. Naming follows standard Go conventions with exported PascalCase types/methods and unexported lowercase internals, and CI is wired through CircleCI rather than GitHub Actions.

API Design The public API favors small, composable primitives over a monolithic client: NextReader/NextWriter expose io.Reader/io.WriteCloser instead of forcing full-message buffering, letting callers stream arbitrarily large messages with constant memory, while ReadJSON/WriteJSON layer on top for the common structured-message case without requiring a separate helper package. Getting started requires little boilerplate beyond declaring an Upgrader and calling Upgrade from an existing net/http handler — there is no required framework, config file, or code generation step. Documentation is unusually thorough for a low-level library, with a multi-section package-level doc comment covering concurrency rules, origin considerations, and buffering behavior that is directly consumable via pkg.go.dev in place of a separate docs site. The one rough edge is concurrency: the API requires callers to manage their own single-reader/single-writer discipline, documented but not enforced by the type system, which is a deliberate performance trade-off rather than an oversight.

Used by 39 apps in this directory

Go
73%
GPL 3.0

1Panel

Devops · Hosting Control Panel · Monitoring

37,044

The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.

View details
91
Repo Health
76
Technical
67
Dependency
Built with
Go 73%
Vue 27%
Updated 1 weeks ago
TypeScript
36%
Other

apptron

Code Editors · Developer Tools

1,210

A full Linux environment with a VSCode-based editor that boots and runs entirely inside your browser tab, no cloud servers required.

View details
49
Repo Health
64
Technical
77
Dependency
Built with
TypeScript 36%
HTML 27%
JavaScript 17%
Updated 2 months ago
Python
55%
Other

authentik

Authentication · Security

25,758

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python 55%
TypeScript 36%
Updated 1 weeks ago
Go
84%
AGPL 3.0

Beta9

AI Development · Automation · Data Engineering

1,794

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
85
Repo Health
78
Technical
66
Dependency
Built with
Go 84%
Python 15%
Updated 1 weeks ago
Go
49%
MIT

Bytebase

Devops

14,512

An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.

View details
92
Repo Health
73
Technical
68
Dependency
Built with
Go 49%
TypeScript 42%
Updated 1 weeks ago
Go
90%
Apache 2.0

CasaOS

File Storage · Hosting Control Panel

37,277

Your simple, elegant personal cloud OS for home data and apps

View details
51
Repo Health
71
Technical
65
Dependency
Built with
Go 90%
Updated 1 years ago
Go
49%
Other

Cosmos-Server

Authentication · Security

6,167

All-in-one self-hosted home server with SmartShield anti-DDoS, Nebula mesh VPN, automatic HTTPS, and a 250-app marketplace — all secured behind a unified auth layer.

View details
83
Repo Health
59
Technical
64
Dependency
Built with
Go 49%
JavaScript 48%
Updated 3 weeks ago
Go
91%
AGPL 3.0

Cozy Stack

File Storage · Productivity

1,270

Self-hosted personal cloud platform that unifies your files, apps, and devices in one private space you fully control.

View details
94
Repo Health
77
Technical
67
Dependency
Built with
Go 91%
Updated 2 weeks ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers