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 ¶
- func DefaultErrorHandler(ctx ErrorContext)
- func Middleware(manager *uow.Manager, cfg Config) func(http.Handler) http.Handler
- func RollbackOn4xx5xx(statusCode int) bool
- func RollbackOn5xx(statusCode int) bool
- func RollbackOnStatusCodes(statusCodes ...int) func(int) bool
- func RollbackOnStatusRange(min, max int) func(int) bool
- func Wrap(manager *uow.Manager, cfg Config, next http.Handler) http.Handler
- type Config
- type ErrorContext
- type ErrorHandler
- type StatusError
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 ¶
Middleware returns a net/http middleware that injects a managed UnitOfWork.
func RollbackOn4xx5xx ¶
RollbackOn4xx5xx rolls back for HTTP 4xx and 5xx responses.
func RollbackOn5xx ¶
RollbackOn5xx rolls back for HTTP 5xx responses.
func RollbackOnStatusCodes ¶
RollbackOnStatusCodes returns a matcher for specific status codes.
func RollbackOnStatusRange ¶
RollbackOnStatusRange returns a matcher for an inclusive status range.
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.
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.