Documentation
¶
Overview ¶
Package events provides a unified event system for real-time catalog updates.
This package implements a broker pattern that connects Starmap's hooks system to multiple transport mechanisms (WebSocket, SSE, etc.) through a common event pipeline. This eliminates code duplication and provides a single point for event distribution.
Index ¶
- type Broker
- func (b *Broker) EventsDropped() uint64
- func (b *Broker) EventsPublished() uint64
- func (b *Broker) Publish(eventType EventType, data any)
- func (b *Broker) QueueDepth() int
- func (b *Broker) Run(ctx context.Context)
- func (b *Broker) Subscribe(sub Subscriber)
- func (b *Broker) SubscriberCount() int
- func (b *Broker) Unsubscribe(sub Subscriber)
- type Event
- type EventType
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker manages event distribution to multiple subscribers. It provides a central hub for catalog events, fanning them out to all registered subscribers (WebSocket, SSE, etc.) concurrently.
func (*Broker) EventsDropped ¶
EventsDropped returns the total number of events dropped.
func (*Broker) EventsPublished ¶
EventsPublished returns the total number of events published.
func (*Broker) QueueDepth ¶
QueueDepth returns the current number of events in the queue.
func (*Broker) Run ¶
Run starts the broker's event loop. Should be called in a goroutine. The broker will run until the context is cancelled.
func (*Broker) Subscribe ¶
func (b *Broker) Subscribe(sub Subscriber)
Subscribe registers a new subscriber to receive events.
func (*Broker) SubscriberCount ¶
SubscriberCount returns the current number of subscribers.
func (*Broker) Unsubscribe ¶
func (b *Broker) Unsubscribe(sub Subscriber)
Unsubscribe removes a subscriber from receiving events.
type Event ¶
type Event struct {
Type EventType `json:"type"`
Timestamp time.Time `json:"timestamp"`
Data any `json:"data"`
}
Event represents a catalog event with type, timestamp, and data.
type EventType ¶
type EventType string
EventType represents the type of catalog event.
const ( // Model events (from Starmap hooks). ModelAdded EventType = "model.added" ModelUpdated EventType = "model.updated" ModelDeleted EventType = "model.deleted" // Sync events (from sync operations). SyncStarted EventType = "sync.started" SyncCompleted EventType = "sync.completed" // Client events (from transport layers). ClientConnected EventType = "client.connected" )
Event types for catalog changes.
type Subscriber ¶
type Subscriber interface {
// Send delivers an event to the subscriber.
// Implementations should be non-blocking and handle errors gracefully.
Send(Event) error
// Close cleanly shuts down the subscriber.
Close() error
}
Subscriber is an interface for event consumers. Implementations adapt the unified event stream to specific transport mechanisms (WebSocket, SSE, MQTT, webhooks, etc.).