events

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus is a simple in-process publish/subscribe event bus. Publish is non-blocking — each handler runs in its own goroutine.

func New

func New(logger *slog.Logger) *Bus

New creates a new Bus.

func (*Bus) Publish

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

Publish sends an event to all registered handlers asynchronously.

func (*Bus) Subscribe

func (b *Bus) Subscribe(h Handler)

Subscribe registers a handler to receive all future events.

type Event

type Event struct {
	Type      Type           `json:"type"`
	Timestamp time.Time      `json:"timestamp"`
	ServiceID string         `json:"service_id,omitempty"`
	Data      map[string]any `json:"data,omitempty"`
}

Event carries the context of something that happened.

type Handler

type Handler func(ctx context.Context, e Event)

Handler is a function that receives events.

type Type

type Type string

Type identifies what happened.

const (
	TypeServiceRegistered     Type = "service_registered"
	TypeServiceDeregistered   Type = "service_deregistered"
	TypeServiceOnline         Type = "service_online"
	TypeServiceOffline        Type = "service_offline"
	TypeServiceDegraded       Type = "service_degraded"
	TypeConfigUpdated         Type = "config_updated"
	TypeConfigDeleted         Type = "config_deleted"
	TypeIndexerCreated        Type = "indexer_created"
	TypeIndexerUpdated        Type = "indexer_updated"
	TypeIndexerDeleted        Type = "indexer_deleted"
	TypeIndexerAssigned       Type = "indexer_assigned"
	TypeIndexerUnassigned     Type = "indexer_unassigned"
	TypeHealthCheck           Type = "health_check"
	TypeQualityProfileCreated Type = "quality_profile_created"
	TypeQualityProfileUpdated Type = "quality_profile_updated"
	TypeQualityProfileDeleted Type = "quality_profile_deleted"
	TypeSharedSettingsUpdated Type = "shared_settings_updated"
)

Jump to

Keyboard shortcuts

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