idempotency

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package idempotency provides idempotency utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHash

func DefaultHash(r *http.Request, body []byte) (string, error)

DefaultHash returns a stable SHA-256 hash of the method, path, query, content type, and body.

Types

type HashFunc

type HashFunc func(*http.Request, []byte) (string, error)

HashFunc computes a request hash used to detect key reuse with different payloads.

type KeyFunc

type KeyFunc func(*http.Request) string

KeyFunc extracts an idempotency key from the request.

type Middleware

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

Middleware enforces Idempotency-Key semantics.

func New

func New(opts Options) (*Middleware, error)

New constructs an idempotency middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler with idempotency logic.

func (*Middleware) Middleware

func (m *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware via Handler adapter.

type Options

type Options struct {
	Store               ports.IdempotencyStore
	HeaderName          string
	KeyFunc             KeyFunc
	HashFunc            HashFunc
	TTL                 time.Duration
	InFlightTTL         time.Duration
	MaxBodyBytes        int64
	Clock               ports.Clock
	ShouldHandle        func(*http.Request) bool
	ShouldStore         func(status int) bool
	ResponseHeaderAllow []string
	ResponseHeaderDeny  []string
	ReplayHeaderName    string
	FailOpen            bool
	OnError             func(error)
}

Options configures the idempotency middleware.

Jump to

Keyboard shortcuts

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