commands

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandLogger

func CommandLogger(provider interfaces.LoggerProvider, module string) interfaces.Logger

CommandLogger returns a module-scoped logger for command handlers, enriching it with consistent structured fields so command executions align with Phase 7 observability.

Types

type Handler

type Handler[T command.Message] struct {
	// contains filtered or unexported fields
}

Handler wraps command execution with shared CMS concerns (context, logging, error tagging).

func NewHandler

func NewHandler[T command.Message](fn command.CommandFunc[T], opts ...HandlerOption[T]) *Handler[T]

NewHandler creates a handler that satisfies go-command's Commander interface while applying CMS-specific concerns (validation, logging, timeout enforcement).

func (*Handler[T]) Execute

func (h *Handler[T]) Execute(ctx context.Context, msg T) error

Execute conforms to command.Commander[T].Execute and applies validation, context management, logging, and error categorisation before delegating to the wrapped function.

type HandlerOption

type HandlerOption[T command.Message] func(*Handler[T])

HandlerOption configures a Handler instance.

func WithLogger

func WithLogger[T command.Message](logger interfaces.Logger) HandlerOption[T]

WithLogger injects the logger used during execution. Defaults to a no-op logger.

func WithMessageFields

func WithMessageFields[T command.Message](extractor func(T) map[string]any) HandlerOption[T]

WithMessageFields attaches message-derived fields to every log entry for the command.

func WithOperation

func WithOperation[T command.Message](operation string) HandlerOption[T]

WithOperation sets a human-friendly operation name emitted with every log entry.

func WithTelemetry

func WithTelemetry[T command.Message](telemetry Telemetry[T]) HandlerOption[T]

WithTelemetry registers an optional telemetry callback invoked after execution completes.

func WithTimeout

func WithTimeout[T command.Message](timeout time.Duration) HandlerOption[T]

WithTimeout overrides the default execution timeout.

type Telemetry

type Telemetry[T command.Message] func(ctx context.Context, msg T, info TelemetryInfo)

Telemetry represents an optional callback invoked after command execution.

func DefaultTelemetry

func DefaultTelemetry[T command.Message](logger interfaces.Logger) Telemetry[T]

DefaultTelemetry returns a telemetry callback that logs command outcomes with the supplied logger.

type TelemetryInfo

type TelemetryInfo struct {
	Command   string
	Operation string
	Fields    map[string]any
	Duration  time.Duration
	Error     error
	Status    TelemetryStatus
	Logger    interfaces.Logger
}

TelemetryInfo describes a command execution outcome provided to telemetry callbacks.

type TelemetryStatus

type TelemetryStatus string

TelemetryStatus captures the result category for command execution.

const (
	// TelemetryStatusSuccess indicates the command completed without errors.
	TelemetryStatusSuccess TelemetryStatus = "success"
	// TelemetryStatusFailed indicates the command execution returned an error.
	TelemetryStatusFailed TelemetryStatus = "failed"
	// TelemetryStatusContextError indicates execution failed due to context cancellation or deadline.
	TelemetryStatusContextError TelemetryStatus = "context_error"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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