persistence

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 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 store.PersistedEvent) (any, error)

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

func FromESEvents

func FromESEvents[T any](events []store.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 store.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 store.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 store.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 store.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](aggregateType string, aggregateID string, events []T, opts ...Option) ([]store.Event, error)

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

func ToUserDeletedV1

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

ToUserDeletedV1 converts a domain event to a store.Event.

func ToUserEmailChangedV1

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

ToUserEmailChangedV1 converts a domain event to a store.Event.

func ToUserRegisteredV1

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

ToUserRegisteredV1 converts a domain event to a store.Event.

func ToUserRegisteredV2

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

ToUserRegisteredV2 converts a domain event to a store.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