Documentation
¶
Overview ¶
Package events defines the event system for Gopherstack. Services can emit typed events and listeners can subscribe to them.
Index ¶
- Variables
- type BucketCreatedEvent
- type BucketDeletedEvent
- type Event
- type EventEmitter
- type EventListener
- type InMemoryEmitter
- type ItemCreatedEvent
- type ItemDeletedEvent
- type ItemUpdatedEvent
- type ObjectCreatedEvent
- type ObjectDeletedEvent
- type S3NotificationEvent
- type SNSMessageAttributeSnapshot
- type SNSPublishedEvent
- type SNSSubscriptionSnapshot
- type TableCreatedEvent
- type TableDeletedEvent
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
ItemCreatedEvent is emitted when an item is added to a DynamoDB table.
func (*ItemCreatedEvent) EventType ¶
func (e *ItemCreatedEvent) EventType() string
type ItemDeletedEvent ¶
ItemDeletedEvent is emitted when an item is deleted from a DynamoDB table.
func (*ItemDeletedEvent) EventType ¶
func (e *ItemDeletedEvent) EventType() string
type ItemUpdatedEvent ¶
ItemUpdatedEvent is emitted when an item in a DynamoDB table is updated.
func (*ItemUpdatedEvent) EventType ¶
func (e *ItemUpdatedEvent) EventType() string
type ObjectCreatedEvent ¶
ObjectCreatedEvent is emitted when an object is added to an S3 bucket.
func (*ObjectCreatedEvent) EventType ¶
func (e *ObjectCreatedEvent) EventType() string
type ObjectDeletedEvent ¶
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 signature of canonical notification string
// SignatureVersion is the AWS SNS SignatureVersion used to produce Signature:
// "1" (SHA1withRSA, the AWS default) or "2" (SHA256withRSA). Consumers that
// re-embed Signature in their own delivery envelope (e.g. SQS) must report
// this same value so the two fields stay consistent.
SignatureVersion 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