decorators

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package decorators provides fluent decorator composition for workflows. Decorators add cross-cutting concerns (logging, metrics) around any interfaces.Workflow implementation without modifying it. The decorator implementations live once in go/foundation/decorator; this package keeps only the workflow-tier fluent builder — its wrap order (ARCHITECTURE.md#decorator-order), its "workflow" labels, and its recovery contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decorate added in v0.3.2

func Decorate[In, Out any](
	wf interfaces.Workflow[In, Out],
	op string,
	logger interfaces.Logger,
	metrics interfaces.Metrics,
	tracer interfaces.Tracer,
	cfg workflowscfg.Config,
) interfaces.Workflow[In, Out]

Decorate wraps wf in the standard workflow stack keyed by op: logging, metrics, tracing, the cfg.Timeout deadline and panic recovery, composed by the Builder in its documented order (recovery outermost). A nil logger, metrics or tracer leaves that layer out, and a zero cfg.Timeout applies no deadline.

Types

type Builder

type Builder[In any, Out any] struct {
	// contains filtered or unexported fields
}

Builder constructs a decorated workflow using the fluent API pattern. Each With* method enables a decorator; Build applies them inside-out: base → timeout → metrics → tracing → logging → recovery (recovery is outermost).

func NewBuilder

func NewBuilder[In, Out any](
	base interfaces.Workflow[In, Out],
	name string,
) *Builder[In, Out]

NewBuilder creates a new decorator builder wrapping the given base workflow. The name is used as a label/prefix for all cross-cutting concerns.

func (*Builder[In, Out]) Build

func (b *Builder[In, Out]) Build() interfaces.Workflow[In, Out]

Build constructs the decorated workflow. Decorators are applied inside-out: base → timeout → metrics → tracing → logging → recovery (recovery is outermost). The composed decorator.Executor satisfies interfaces.Workflow (identical method set).

func (*Builder[In, Out]) WithLogging

func (b *Builder[In, Out]) WithLogging(logger interfaces.Logger) *Builder[In, Out]

WithLogging adds a logging decorator that logs execution entry and failures at Debug level (failures are suppressed in staging/prod where level=info; the error is logged once at the transport layer instead of at every decorator tier).

func (*Builder[In, Out]) WithMetrics

func (b *Builder[In, Out]) WithMetrics(m interfaces.Metrics) *Builder[In, Out]

WithMetrics adds a metrics decorator that records execution counts and durations via the interfaces.Metrics abstraction.

func (*Builder[In, Out]) WithRecovery

func (b *Builder[In, Out]) WithRecovery() *Builder[In, Out]

WithRecovery adds a recovery decorator that catches panics and converts them to errors.

func (*Builder[In, Out]) WithTimeout

func (b *Builder[In, Out]) WithTimeout(d time.Duration) *Builder[In, Out]

WithTimeout adds a timeout decorator that enforces a per-execution deadline.

func (*Builder[In, Out]) WithTracing

func (b *Builder[In, Out]) WithTracing(tracer interfaces.Tracer) *Builder[In, Out]

WithTracing adds a tracing decorator that creates a span per workflow execution, so the request cascade is visible in Tempo.

Jump to

Keyboard shortcuts

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