persistence

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventTypeOf

func EventTypeOf(e any) (string, error)

EventTypeOf returns the event type string for a given domain event. The event type is the struct name without version information.

func FromESEvent

func FromESEvent(pe es.PersistedEvent) (any, error)

FromESEvent converts a single persisted event to a domain event. This is useful for projection handlers that need to convert individual events.

func FromESEvents

func FromESEvents[T any](events []es.PersistedEvent) ([]T, error)

FromESEvents converts persisted events back to domain events. The function uses generics to return a strongly-typed slice. T must be 'any' or a common interface implemented by all domain events.

func FromUserDeletedV1

func FromUserDeletedV1(pe es.PersistedEvent) (v1.UserDeleted, error)

FromUserDeletedV1 converts a persisted event to a domain event. Returns an error if the event type or version doesn't match.

func FromUserEmailChangedV1

func FromUserEmailChangedV1(pe es.PersistedEvent) (v1.UserEmailChanged, error)

FromUserEmailChangedV1 converts a persisted event to a domain event. Returns an error if the event type or version doesn't match.

func FromUserRegisteredV1

func FromUserRegisteredV1(pe es.PersistedEvent) (v1.UserRegistered, error)

FromUserRegisteredV1 converts a persisted event to a domain event. Returns an error if the event type or version doesn't match.

func FromUserRegisteredV2

func FromUserRegisteredV2(pe es.PersistedEvent) (v2.UserRegistered, error)

FromUserRegisteredV2 converts a persisted event to a domain event. Returns an error if the event type or version doesn't match.

func ToESEvents

func ToESEvents[T any](boundedContext string, aggregateType string, aggregateID string, events []T, opts ...Option) ([]es.Event, error)

ToESEvents converts domain events to es.Event instances. Each domain event is marshaled to JSON and wrapped in an es.Event. The generic type T allows for type-safe event slices instead of []any.

func ToUserDeletedV1

func ToUserDeletedV1(boundedContext string, aggregateType string, aggregateID string, e v1.UserDeleted, opts ...Option) (es.Event, error)

ToUserDeletedV1 converts a domain event to an es.Event.

func ToUserEmailChangedV1

func ToUserEmailChangedV1(boundedContext string, aggregateType string, aggregateID string, e v1.UserEmailChanged, opts ...Option) (es.Event, error)

ToUserEmailChangedV1 converts a domain event to an es.Event.

func ToUserRegisteredV1

func ToUserRegisteredV1(boundedContext string, aggregateType string, aggregateID string, e v1.UserRegistered, opts ...Option) (es.Event, error)

ToUserRegisteredV1 converts a domain event to an es.Event.

func ToUserRegisteredV2

func ToUserRegisteredV2(boundedContext string, aggregateType string, aggregateID string, e v2.UserRegistered, opts ...Option) (es.Event, error)

ToUserRegisteredV2 converts a domain event to an es.Event.

Types

type Option

type Option func(*eventOptions)

Option is a functional option for configuring event metadata.

func WithCausationID

func WithCausationID(id string) Option

WithCausationID sets the causation ID for the event.

func WithCorrelationID

func WithCorrelationID(id string) Option

WithCorrelationID sets the correlation ID for the event.

func WithMetadata

func WithMetadata(metadata []byte) Option

WithMetadata sets custom metadata for the event.

func WithTraceID

func WithTraceID(id string) Option

WithTraceID sets the trace ID for the event.

Jump to

Keyboard shortcuts

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