Documentation
¶
Overview ¶
Package idempotency provides HTTP middleware that implements the Idempotency-Key header semantics (Stripe-style). When a client retries a request with the same key + same body, the server replays the original response byte-for-byte instead of executing again.
Storage is provided by the service (per-schema table) via the Store interface. The middleware is opt-in per service via Require(store, ...).
Default behavior: applies to POST/PUT/PATCH/DELETE; bypasses GET/HEAD/OPTIONS. Use WithExclude to bypass specific routes (e.g., auth flows).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("idempotency: record not found")
ErrNotFound is returned by Store.Get when no record exists for the key.
Functions ¶
func FromContext ¶
FromContext extracts the org_id from the request context. Returns false when absent — middleware will bypass idempotency in that case.
Types ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory Store for testing only.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
type Option ¶
type Option func(*config)
func WithExclude ¶
WithExclude bypasses the middleware for the given routes. Format: "METHOD /path" (e.g., "POST /v1/auth/login").