Help us shape the future of Go! Take the 2026 Go Developer Survey

events

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package events provides an in-process publish/subscribe bus used to push notify-only realtime updates to UI clients via WebSocket. Events carry only type/topic metadata; consumers refetch via REST to read current state.

Index

Constants

View Source
const (
	TopicGlobalApps       = "global:apps"
	TopicGlobalSettings   = "global:settings"
	TopicGlobalUsers      = "global:users"
	TopicGlobalRegistries = "global:registries"
	TopicGlobalAlerts     = "global:alerts"
	TopicGlobalBackups    = "global:backups"
	TopicGlobalDocker     = "global:docker"
	TopicGlobalAudit      = "global:audit"
)

Topic constants for the global scopes. Per-app topics are formed via AppTopic.

Variables

This section is empty.

Functions

func AppTopic

func AppTopic(slug string) string

AppTopic returns the per-app topic string for a slug.

func TopicsForAudit

func TopicsForAudit(category, action, slug string) []string

TopicsForAudit returns the list of topics that should fire for a given audit category, action, and (optional) app slug. Used by the audit recorder to translate mutation events into bus publishes.

func TypeForCategory

func TypeForCategory(category string) string

TypeForCategory returns the canonical event type string for an audit category, used as the "type" field in the WS frame.

Types

type Bus

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

Bus is a single-process fan-out bus. Safe for concurrent use.

func New

func New() *Bus

New constructs an empty Bus.

func (*Bus) Publish

func (b *Bus) Publish(_ context.Context, e Event)

Publish fans an event out to every subscriber whose filter accepts it. Never blocks: if a subscriber's buffer is full, the oldest event is discarded and the subscriber's stale flag is set.

func (*Bus) Subscribe

func (b *Bus) Subscribe(filter func(Event) bool) (<-chan Event, func(), *subscriber)

Subscribe registers a new subscriber. filter is evaluated server-side at publish time so events that fail filter never reach the channel; pass nil to receive all events. The returned cancel function unsubscribes and closes the channel; calling it more than once is safe.

The returned read-only channel has buffer 64. On overflow, the oldest event is dropped and Stale() returns true so the handler can emit a synthetic resync frame.

type Event

type Event struct {
	Type    string    `json:"type"`
	Topic   string    `json:"topic"`
	ActorID *int64    `json:"actor_id,omitempty"`
	Ts      time.Time `json:"ts"`
}

Event is a single notify-only message broadcast on the bus. Type is a coarse classification (e.g. "app.changed", "app.status"). Topic identifies the resource scope (e.g. "app:foo", "global:settings"). No payload data ships in events; clients refetch the relevant REST resource.

Jump to

Keyboard shortcuts

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