events

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package events defines the event system for Gopherstack. Services can emit typed events and listeners can subscribe to them.

Index

Constants

This section is empty.

Variables

View Source
var ErrListenerPanicked = errors.New("listener panicked")

ErrListenerPanicked is returned by Emit when a listener function panics. Callers can use errors.Is to detect this condition.

Functions

This section is empty.

Types

type BucketCreatedEvent

type BucketCreatedEvent struct {
	BucketName string
}

BucketCreatedEvent is emitted when an S3 bucket is created.

func (*BucketCreatedEvent) EventType

func (e *BucketCreatedEvent) EventType() string

type BucketDeletedEvent

type BucketDeletedEvent struct {
	BucketName string
}

BucketDeletedEvent is emitted when an S3 bucket is deleted.

func (*BucketDeletedEvent) EventType

func (e *BucketDeletedEvent) EventType() string

type Event

type Event interface {
	EventType() string
}

Event is a marker interface for all events in the system. All concrete event types must implement this interface.

type EventEmitter

type EventEmitter[T Event] interface {
	Emit(ctx context.Context, event T) error
	Subscribe(listener EventListener[T]) func()
	ListenerCount() int
}

EventEmitter manages event subscriptions and delivery.

type EventListener

type EventListener[T Event] func(ctx context.Context, event T) error

EventListener is a callback function that handles a specific event type.

type InMemoryEmitter

type InMemoryEmitter[T Event] struct {
	// contains filtered or unexported fields
}

InMemoryEmitter is a simple in-memory implementation of the EventEmitter interface. It stores listeners and emits events synchronously to all subscribers.

func NewInMemoryEmitter

func NewInMemoryEmitter[T Event]() *InMemoryEmitter[T]

NewInMemoryEmitter creates a new in-memory event emitter.

func (*InMemoryEmitter[T]) Clear

func (e *InMemoryEmitter[T]) Clear()

Clear removes all listeners from the emitter. Useful for testing.

func (*InMemoryEmitter[T]) Close

func (e *InMemoryEmitter[T]) Close()

Close releases the Prometheus metric series associated with the emitter's internal lock. Call Close when the emitter is no longer needed to prevent metric leaks.

func (*InMemoryEmitter[T]) Emit

func (e *InMemoryEmitter[T]) Emit(ctx context.Context, event T) error

Emit broadcasts an event to all subscribers synchronously. Returns the first non-nil error encountered, if any. If a listener panics, the panic is recovered and returned as an error.

func (*InMemoryEmitter[T]) ListenerCount

func (e *InMemoryEmitter[T]) ListenerCount() int

ListenerCount returns the current number of registered listeners.

func (*InMemoryEmitter[T]) Subscribe

func (e *InMemoryEmitter[T]) Subscribe(listener EventListener[T]) func()

Subscribe adds a listener to the emitter and returns an unsubscribe function.

type ItemCreatedEvent

type ItemCreatedEvent struct {
	Key   map[string]any
	Table string
}

ItemCreatedEvent is emitted when an item is added to a DynamoDB table.

func (*ItemCreatedEvent) EventType

func (e *ItemCreatedEvent) EventType() string

type ItemDeletedEvent

type ItemDeletedEvent struct {
	Key   map[string]any
	Table string
}

ItemDeletedEvent is emitted when an item is deleted from a DynamoDB table.

func (*ItemDeletedEvent) EventType

func (e *ItemDeletedEvent) EventType() string

type ItemUpdatedEvent

type ItemUpdatedEvent struct {
	Key   map[string]any
	Table string
}

ItemUpdatedEvent is emitted when an item in a DynamoDB table is updated.

func (*ItemUpdatedEvent) EventType

func (e *ItemUpdatedEvent) EventType() string

type ObjectCreatedEvent

type ObjectCreatedEvent struct {
	BucketName string
	Key        string
	Size       int64
}

ObjectCreatedEvent is emitted when an object is added to an S3 bucket.

func (*ObjectCreatedEvent) EventType

func (e *ObjectCreatedEvent) EventType() string

type ObjectDeletedEvent

type ObjectDeletedEvent struct {
	BucketName string
	Key        string
}

ObjectDeletedEvent is emitted when an object is deleted from an S3 bucket.

func (*ObjectDeletedEvent) EventType

func (e *ObjectDeletedEvent) EventType() string

type S3NotificationEvent

type S3NotificationEvent struct {
	// Payload is the JSON-encoded S3 event notification body (Records array).
	Payload string
	// TargetARN is the destination ARN (SQS queue ARN, SNS topic ARN, Lambda function ARN).
	TargetARN string
	// TargetType is the notification target type: "sqs", "sns", or "lambda".
	TargetType string
}

S3NotificationEvent is emitted when an S3 notification must be delivered to external targets (SQS, SNS, Lambda) configured via PutBucketNotificationConfiguration. The Payload field contains the standard AWS S3 event notification JSON (Records array).

func (*S3NotificationEvent) EventType

func (e *S3NotificationEvent) EventType() string

type SNSMessageAttributeSnapshot

type SNSMessageAttributeSnapshot struct {
	// DataType is the attribute data type (String, Number, Binary, …).
	DataType string
	// StringValue is the string value (set when DataType is String/Number).
	StringValue string
}

SNSMessageAttributeSnapshot holds a single message attribute value.

type SNSPublishedEvent

type SNSPublishedEvent struct {
	Attributes     map[string]SNSMessageAttributeSnapshot
	TopicARN       string
	MessageID      string
	Message        string
	Subject        string
	Timestamp      string // RFC3339 timestamp fixed at publish time (used for signing)
	Signature      string // base64 RSA-SHA1 signature of canonical notification string
	SigningCertURL string // URL where the signing certificate PEM can be retrieved
	Subscriptions  []SNSSubscriptionSnapshot
}

SNSPublishedEvent is emitted whenever a message is published to an SNS topic. Listeners (e.g. SQS) can subscribe to deliver the message to the appropriate endpoints.

func (*SNSPublishedEvent) EventType

func (e *SNSPublishedEvent) EventType() string

type SNSSubscriptionSnapshot

type SNSSubscriptionSnapshot struct {
	SubscriptionARN    string
	Protocol           string
	Endpoint           string
	FilterPolicy       string
	RedrivePolicy      string
	DeliveryPolicy     string
	RawMessageDelivery bool
}

SNSSubscriptionSnapshot holds subscription metadata at publish time.

type TableCreatedEvent

type TableCreatedEvent struct {
	Table string
}

TableCreatedEvent is emitted when a DynamoDB table is created.

func (*TableCreatedEvent) EventType

func (e *TableCreatedEvent) EventType() string

type TableDeletedEvent

type TableDeletedEvent struct {
	Table string
}

TableDeletedEvent is emitted when a DynamoDB table is deleted.

func (*TableDeletedEvent) EventType

func (e *TableDeletedEvent) EventType() string

Jump to

Keyboard shortcuts

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