ws

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpgradeHandler

func UpgradeHandler(hub *Hub) http.HandlerFunc

UpgradeHandler returns an http.HandlerFunc that upgrades the connection to WebSocket.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a middleman between the WebSocket connection and the hub.

func NewClient

func NewClient(hub *Hub, tenantID string, conn *websocket.Conn) *Client

NewClient creates a new WebSocket client.

type Event

type Event struct {
	TenantID string // target tenant; required
	Type     string // e.g. "balance_updated", "income_received", "snapshot_ready"
	Payload  string // pre-rendered HTML fragment with hx-swap-oob attribute
}

Event represents a push notification to be delivered to browser clients.

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub maintains the set of active clients and broadcasts messages to them.

func NewHub

func NewHub(maxConnsPerTenant int) *Hub

NewHub creates a new WebSocket hub.

func (*Hub) Publish

func (h *Hub) Publish(event Event) error

Publish sends an event to the hub for broadcasting.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run starts the hub's main event loop.

type InProcessPublisher

type InProcessPublisher struct {
	// contains filtered or unexported fields
}

InProcessPublisher is a basic implementation of Publisher that forwards events to the Hub.

func NewInProcessPublisher

func NewInProcessPublisher(hub *Hub) *InProcessPublisher

NewInProcessPublisher creates a new InProcessPublisher.

func (*InProcessPublisher) Publish

func (p *InProcessPublisher) Publish(_ context.Context, event Event) error

Publish sends an event to the Hub's broadcast channel.

type Publisher

type Publisher interface {
	// Publish sends an event to all WebSocket clients of the given tenant.
	Publish(ctx context.Context, event Event) error
}

Publisher is the interface through which other services push events to connected clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL