lifecycle

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureHook

type CaptureHook struct {
	Events []Event
	Err    error
	// contains filtered or unexported fields
}

CaptureHook records events for assertions in tests.

func (*CaptureHook) Notify

func (h *CaptureHook) Notify(_ context.Context, event Event) error

Notify records the event and returns any configured error.

type Config

type Config struct {
	Enabled bool
}

Config controls lifecycle emission defaults supplied by DI/config.

type Emitter

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

Emitter fans out lifecycle events to hooks.

func NewEmitter

func NewEmitter(hooks Hooks, cfg Config) *Emitter

NewEmitter constructs an emitter from hooks and configuration.

func (*Emitter) Emit

func (e *Emitter) Emit(ctx context.Context, event Event) error

Emit forwards the event to all hooks.

func (*Emitter) Enabled

func (e *Emitter) Enabled() bool

Enabled reports whether emissions should be attempted.

type Event

type Event struct {
	ResourceType    string
	RecordID        string
	Transition      string
	TranslationID   string
	Locale          string
	Locales         []string
	Status          string
	EnvironmentKey  string
	ContentTypeID   string
	ContentTypeSlug string
	SearchEnabled   bool
	SearchIndex     string
	OccurredAt      time.Time
	Metadata        map[string]any
}

Event describes a root-record lifecycle transition that downstream systems can consume.

func NormalizeEvent

func NormalizeEvent(event Event) Event

NormalizeEvent trims string fields, clones slices/maps, and ensures a timestamp is present.

type Hook

type Hook interface {
	Notify(ctx context.Context, event Event) error
}

Hook receives normalized lifecycle events.

type HookFunc

type HookFunc func(ctx context.Context, event Event) error

HookFunc allows plain functions to satisfy Hook.

func (HookFunc) Notify

func (fn HookFunc) Notify(ctx context.Context, event Event) error

Notify dispatches to the underlying function.

type Hooks

type Hooks []Hook

Hooks fans out events to zero or more hooks.

func (Hooks) Enabled

func (h Hooks) Enabled() bool

Enabled reports whether there are any hooks to notify.

func (Hooks) Notify

func (h Hooks) Notify(ctx context.Context, event Event) error

Notify forwards the event to all hooks, returning a joined error if any fail.

Jump to

Keyboard shortcuts

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