middleware

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package middleware provides composable middleware for the Weave pipeline. Middleware wraps pipeline step execution, enabling cross-cutting concerns like caching, tracing, and tenant isolation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache provides a simple in-memory cache middleware for pipeline steps. It caches step results keyed by the step name and a hash of the StepContext contents.

func NewCache

func NewCache() *Cache

NewCache creates a new cache middleware.

func (*Cache) Clear

func (c *Cache) Clear()

Clear empties the cache.

func (*Cache) Middleware

func (c *Cache) Middleware(names ...string) Middleware

Middleware returns a Middleware that caches step outputs. Only steps whose names match one of the given names are cached. If no names are provided, all steps are cached.

type LogTracer

type LogTracer struct {
	Printf func(format string, args ...any)
}

LogTracer is a simple TracingHook that prints to a function.

func (*LogTracer) AfterStep

func (t *LogTracer) AfterStep(_ context.Context, stepName string, err error)

AfterStep logs the completion of a step.

func (*LogTracer) BeforeStep

func (t *LogTracer) BeforeStep(_ context.Context, stepName string)

BeforeStep logs the start of a step.

type Middleware

type Middleware func(next StepHandler) StepHandler

Middleware wraps step execution.

func Chain

func Chain(mws ...Middleware) Middleware

Chain composes multiple middleware into a single Middleware. Middleware are applied left-to-right: the first middleware in the chain is the outermost wrapper.

func Tenant

func Tenant() Middleware

Tenant returns a Middleware that extracts the tenant from the context and injects it into the pipeline step context under the standard tenant_id key.

func Tracing

func Tracing(hook TracingHook) Middleware

Tracing returns a Middleware that calls the given hook before and after each pipeline step.

type StepHandler

type StepHandler func(ctx context.Context, sc *pipeline.StepContext) error

StepHandler executes a pipeline step.

type TracingHook

type TracingHook interface {
	// BeforeStep is called before a pipeline step executes.
	BeforeStep(ctx context.Context, stepName string)
	// AfterStep is called after a pipeline step completes.
	AfterStep(ctx context.Context, stepName string, err error)
}

TracingHook is called before and after each step for custom tracing.

Jump to

Keyboard shortcuts

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