domain

package
v0.0.0-...-7827b3b Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEventName     = errors.New("invalid event name")
	ErrInvalidEventProducer = errors.New("invalid event producer")
	ErrInvalidEventTime     = errors.New("invalid event time")
	ErrInvalidEventID       = errors.New("invalid event id")
	ErrInvalidEventSchema   = errors.New("invalid event schema version")
)

Детализация причины (удобно для логов/диагностики)

View Source
var ErrInvalidEvent = errors.New("invalid event")

Sentinel error (удобно для errors.Is)

Functions

This section is empty.

Types

type BaseEvent

type BaseEvent struct {
	// Core
	Name string
	At   time.Time

	// Idempotency / tracing
	ID            uuid.UUID
	TraceID       string
	CorrelationID string
	CausationID   uuid.UUID

	// Compatibility
	SchemaVersion int32

	// Producer metadata
	Producer string

	// Extensible, non-PII
	Meta map[string]string
}

BaseEvent — базовая мета-информация любого события. Не содержит бизнес-данных и не привязан к Kafka/Transport.

func MustBaseEvent

func MustBaseEvent(name, producer string) BaseEvent

MustBaseEvent — удобный хелпер для мест, где name/producer константы.

func NewBaseEvent

func NewBaseEvent(name, producer string) (BaseEvent, error)

NewBaseEvent — безопасный конструктор (UTC + UUID + schema v1).

func (BaseEvent) EventID

func (e BaseEvent) EventID() uuid.UUID

func (BaseEvent) EventName

func (e BaseEvent) EventName() string

Interface implementation

func (BaseEvent) OccurredAt

func (e BaseEvent) OccurredAt() time.Time

func (BaseEvent) SchemaVer

func (e BaseEvent) SchemaVer() int32

func (BaseEvent) Validate

func (e BaseEvent) Validate() error

Validate — строгая проверка инвариантов события. Возвращает ErrInvalidEvent (sentinel) с детализацией причины.

func (BaseEvent) WithCausation

func (e BaseEvent) WithCausation(id uuid.UUID) BaseEvent

WithCausation — указать "что стало причиной" (например, EventID родительского события или CommandID).

func (BaseEvent) WithMeta

func (e BaseEvent) WithMeta(k, v string) BaseEvent

WithMeta — copy-on-write для карты, чтобы не было скрытого шаринга.

func (BaseEvent) WithSchema

func (e BaseEvent) WithSchema(ver int32) BaseEvent

func (BaseEvent) WithTrace

func (e BaseEvent) WithTrace(traceID, correlationID string) BaseEvent

WithTrace — добавить trace/correlation (обычно выставляется в UC из контекста запроса).

type Event

type Event interface {
	EventName() string
	OccurredAt() time.Time
	EventID() uuid.UUID
	SchemaVer() int32
}

type EventBuffer

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

func (*EventBuffer) Clear

func (b *EventBuffer) Clear()

func (*EventBuffer) Len

func (b *EventBuffer) Len() int

func (*EventBuffer) Peek

func (b *EventBuffer) Peek() []Event

Peek — посмотреть без очистки (копия, чтобы снаружи не мутировали slice).

func (*EventBuffer) Pull

func (b *EventBuffer) Pull() []Event

Pull — забрать и очистить.

func (*EventBuffer) Record

func (b *EventBuffer) Record(e Event)

Jump to

Keyboard shortcuts

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