events

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEvent

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

BaseEvent provides common event functionality

func NewBaseEvent

func NewBaseEvent(eventType string) BaseEvent

NewBaseEvent creates a new base event

func (BaseEvent) EventID

func (e BaseEvent) EventID() string

EventID returns the event ID

func (BaseEvent) EventType

func (e BaseEvent) EventType() string

EventType returns the event type

func (BaseEvent) Timestamp

func (e BaseEvent) Timestamp() time.Time

Timestamp returns the event timestamp

type DispatchError

type DispatchError struct {
	Errors []error
}

DispatchError represents errors that occurred during event dispatch

func (*DispatchError) Error

func (e *DispatchError) Error() string

type Event

type Event interface {
	// EventID returns the unique identifier of the event
	EventID() string
	// EventType returns the type of the event
	EventType() string
	// Timestamp returns when the event occurred
	Timestamp() time.Time
	// Data returns the event data
	Data() any
}

Event represents a domain event

type EventDispatcher

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

EventDispatcher dispatches events to registered handlers

func NewEventDispatcher

func NewEventDispatcher() *EventDispatcher

NewEventDispatcher creates a new event dispatcher

func (*EventDispatcher) Dispatch

func (d *EventDispatcher) Dispatch(ctx context.Context, event Event) error

Dispatch dispatches an event to all registered handlers

func (*EventDispatcher) RegisterHandler

func (d *EventDispatcher) RegisterHandler(eventType string, handler EventHandler)

RegisterHandler registers an event handler for a specific event type

type EventHandler

type EventHandler interface {
	// Handle processes the event
	Handle(ctx context.Context, event Event) error
}

EventHandler handles domain events

type EventStore

type EventStore interface {
	// Save saves an event
	Save(ctx context.Context, event Event) error
	// Load loads events for an aggregate
	Load(ctx context.Context, aggregateID string) ([]Event, error)
}

EventStore stores events for later retrieval

type InMemoryEventStore

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

InMemoryEventStore implements EventStore using memory

func NewInMemoryEventStore

func NewInMemoryEventStore() *InMemoryEventStore

NewInMemoryEventStore creates a new in-memory event store

func (*InMemoryEventStore) Load

func (s *InMemoryEventStore) Load(ctx context.Context, aggregateID string) ([]Event, error)

Load loads events for an aggregate

func (*InMemoryEventStore) Save

func (s *InMemoryEventStore) Save(ctx context.Context, event Event) error

Save saves an event

Jump to

Keyboard shortcuts

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