events

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package events fans server events out to connected clients (the server-sent event stream). Every event says who may see it, so each user's stream only carries their own and shared events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Audience

type Audience struct {
	// All users.
	All bool
	// Admins (always included when All).
	Admins bool
	// Users by ID.
	Users []uuid.UUID
}

Audience says who may receive an event.

type Event

type Event struct {
	// ID increases across the server's life.
	ID   int64
	Type string
	Data any
	To   Audience
}

Event is one server event.

type Hub

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

Hub fans events out. Publishing never blocks: a subscriber that falls behind is dropped (its stream ends, and the client reconnects and refetches).

func NewHub

func NewHub() *Hub

NewHub returns an empty hub.

func (*Hub) Publish

func (h *Hub) Publish(typ string, data any, to Audience)

Publish sends an event to every subscriber allowed to see it. Safe on a nil hub.

func (*Hub) Subscribe

func (h *Hub) Subscribe(v Viewer) *Subscription

Subscribe starts receiving events for v. Call Close when done.

func (*Hub) Subscribers

func (h *Hub) Subscribers() int

Subscribers counts live subscriptions.

type Subscription

type Subscription struct {
	C chan Event
	// contains filtered or unexported fields
}

Subscription receives the events its viewer may see.

func (*Subscription) Close

func (s *Subscription) Close()

Close stops the subscription and closes C.

type Viewer

type Viewer struct {
	UserID uuid.UUID
	Admin  bool
}

Viewer is a subscriber's identity.

Jump to

Keyboard shortcuts

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