httpuow

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpuow provides net/http integration for github.com/pakasa-io/uow.

The package keeps transport-specific policy, such as status-based rollback decisions, out of the core uow package while using the same ambient execution path as other owners.

Transactional handlers are response-buffered until finalization so commit or rollback failures can still affect the HTTP result. Streaming, hijacking, and similar long-lived response patterns should opt out of managed transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorHandler

func DefaultErrorHandler(ctx ErrorContext)

DefaultErrorHandler preserves status-based rollback responses when possible and otherwise returns HTTP 500 when the response has not started yet.

func Middleware

func Middleware(manager *uow.Manager, cfg Config) func(http.Handler) http.Handler

Middleware returns a net/http middleware that injects a managed UnitOfWork.

func RollbackOn4xx5xx

func RollbackOn4xx5xx(statusCode int) bool

RollbackOn4xx5xx rolls back for HTTP 4xx and 5xx responses.

func RollbackOn5xx

func RollbackOn5xx(statusCode int) bool

RollbackOn5xx rolls back for HTTP 5xx responses.

func RollbackOnStatusCodes

func RollbackOnStatusCodes(statusCodes ...int) func(int) bool

RollbackOnStatusCodes returns a matcher for specific status codes.

func RollbackOnStatusRange

func RollbackOnStatusRange(min, max int) func(int) bool

RollbackOnStatusRange returns a matcher for an inclusive status range.

func Wrap

func Wrap(manager *uow.Manager, cfg Config, next http.Handler) http.Handler

Wrap applies Config to one HTTP handler.

Types

type Config

type Config struct {
	Execution              uow.ExecutionConfig
	ResolveExecution       func(*http.Request) (uow.ExecutionConfig, error)
	ResolveTenant          func(*http.Request) (string, error)
	ResolveBindingOverride func(*http.Request) (uow.BindingOverride, bool, error)
	RollbackOnStatus       func(int) bool
	ErrorHandler           ErrorHandler
}

Config controls per-handler and per-request HTTP integration behavior.

func (Config) Validate added in v1.1.0

func (c Config) Validate() error

Validate validates the static portion of the HTTP integration config.

When ResolveExecution is set, execution settings are validated per request.

type ErrorContext

type ErrorContext struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	Err            error
	StatusCode     int
	Started        bool
}

ErrorContext describes an integration error after managed execution.

type ErrorHandler

type ErrorHandler func(ErrorContext)

ErrorHandler handles integration and finalization failures.

type StatusError

type StatusError struct {
	StatusCode int
}

StatusError marks a transport-driven rollback decision derived from an HTTP status code.

func (*StatusError) Error

func (e *StatusError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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