Realtime WebSocket Events for Go
Publish real-time WebSocket events from Go HTTP handlers, background workers, or CLI tools. Stdlib-only server SDK — zero external dependencies, context-aware, idiomatic error handling.
go get github.com/apinator-io/sdk-go npm install @apinator/client Publishing real-time WebSocket events from a Go service requires no additional infrastructure when you use Apinator. Make a single API call from any HTTP handler or goroutine to deliver an event to all subscribed browser clients. The Go SDK uses only the standard library — net/http, crypto/hmac, encoding/json — and adds zero dependencies to your go.mod file.
Quick Start
How to publish realtime WebSocket events from Go
Add realtime features to your Go app in a few steps.
Install the Go SDK
Add the module to your project. Zero dependencies — stdlib only.
Create a client
Initialize with app credentials and cluster. Uses the standard http.Client under the hood.
Trigger WebSocket events
Publish real-time WebSocket events from HTTP handlers, background goroutines, or CLI tools. All subscribed clients receive the event instantly.
Authenticate channels
Add an HTTP handler that authenticates private channel subscriptions.
Why Go
Built for Go developers
Stdlib Only
Zero external dependencies. Uses net/http, crypto/hmac, and encoding/json from the standard library.
Context-Aware
All API methods accept context.Context for timeouts, cancellation, and tracing integration.
Functional Options
Configure with WithHost(), WithHTTPClient(), and more. Clean, extensible API without config structs.
Idiomatic Errors
Typed error types (AuthenticationError, ValidationError, ApiError) that work with errors.Is/As.
How WebSocket event publishing works from Go
A common pattern for Go web services is to push real-time updates to connected browser clients — for example, sending a dashboard update when a background job completes, or notifying users when an order status changes. The traditional approach requires running a WebSocket server alongside your Go HTTP server and managing client connections in memory, which adds complexity around connection state, scaling, and graceful shutdown.
Apinator separates the concerns cleanly: your Go service handles its domain logic and publishes events via a single HTTPS API call. Apinator's servers maintain the persistent WebSocket connections to browser clients and deliver the event in real-time, typically in under 100ms. Your Go service remains stateless with respect to WebSocket connections, which simplifies horizontal scaling — no sticky sessions required, no in-memory fan-out to coordinate.
The Go SDK wraps this API call idiomatically. All methods accept context.Context for cancellation and timeout propagation. Errors are typed so you can use errors.Is and errors.As. Configuration uses the functional options pattern — WithHost(), WithHTTPClient() — keeping the API clean and extensible. There are zero external dependencies; the module uses only Go's standard library.
Full Example
Full Example: Realtime WebSocket Events from a Go HTTP Server
Complete WebSocket example: Go HTTP handlers for private channel authentication and event publishing, plus a JavaScript frontend that receives real-time updates.
Related Docs
Read the core WebSocket guides
Related Use Cases
Explore realtime use cases
Start building realtime Go apps
Completely free. No credit card. No catch.