Documentation
¶
Overview ¶
Package ws is a channel-based WebSocket transport for togo realtime. It supports public and private channels, signed connection tickets (so private channels are authenticated and scoped to the channels the ticket was granted), and channel-scoped broadcasting. It implements togo.Broker and overrides the default SSE broker when installed.
Publish uses an event of the form "channel:event" to target a channel (private channels are prefixed "private-"); an event with no ":" broadcasts to every connection that presented a valid ticket (unauthenticated connections never see unchanneled broadcasts).
Install: `togo install togo-framework/realtime-ws`. Env: REALTIME_SECRET, REALTIME_ORIGINS.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IssueTicket ¶ added in v0.4.0
func IssueTicket(w http.ResponseWriter, r *http.Request)
IssueTicket returns a signed ticket for private-channel access. Mount it behind the app's auth middleware — see MountTicket — so only authenticated users receive one.
The channels it grants come from SetTicketChannels, called with this request. If SetTicketChannels was never configured, the ticket grants no private channels (secure by default) and a one-time warning is logged.
func IssueTicketFor ¶ added in v0.4.0
func IssueTicketFor(w http.ResponseWriter, channels []string)
IssueTicketFor writes a ticket granting exactly the given channels. Use it to hand-roll ticket issuance instead of going through SetTicketChannels.
func MountTicket ¶ added in v0.4.0
MountTicket mounts IssueTicket at /events/ticket wrapped in the middleware you pass — which should be your auth, so only authenticated users get a ticket.
The provider deliberately does not do this for you. A provider that mounts a route makes chi's mux "have routes", and any plugin that later calls Router.Use — togo's own auth plugin does, for CORS — then panics with "chi: all middlewares must be defined before routes on a mux". Leaving the mount to the app means this package cannot break another plugin's boot, at any provider priority, in any order.
func SetTicketChannels ¶ added in v0.4.0
SetTicketChannels registers the function IssueTicket (and so MountTicket) uses to decide which channels the requesting user's ticket is granted. f is called per request and should return the exact channel names and/or "prefix*" globs the caller may subscribe to (typically their own private-* channels).
If this is never called, IssueTicket grants no private channels — secure by default — and logs a one-time warning explaining that SetTicketChannels needs to be configured to unlock private-channel access.
Types ¶
This section is empty.