Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
func NewMiddleware(cfg ...Config) fh.HandlerFunc
New is a convenience function that creates and returns middleware.
Types ¶
type Config ¶
type Config struct {
// Window is the time window during which duplicate requests are detected.
// Default: 5 seconds.
Window time.Duration
// MaxKeys is the maximum number of dedup keys stored before eviction.
// Default: 10000.
MaxKeys int
// KeyFunc extracts the dedup key from the request. The default computes
// SHA-256(method + path + body).
KeyFunc func(fh.Ctx) string
// OnDuplicate is called when a duplicate request is detected. The default
// returns 409 Conflict with the original request's response.
OnDuplicate func(fh.Ctx, *Entry) error
}
Config controls deduplication behavior.
type Deduplicator ¶
type Deduplicator struct {
// contains filtered or unexported fields
}
Deduplicator tracks in-flight requests and deduplicates within a window.
func New ¶
func New(cfg ...Config) *Deduplicator
New creates a deduplicator. If cfg is zero, defaults are applied.
func (*Deduplicator) Handler ¶
func (d *Deduplicator) Handler() fh.HandlerFunc
Handler returns middleware that deduplicates requests within the configured window.
func (*Deduplicator) Stats ¶
func (d *Deduplicator) Stats() (active int, evictions int)
Stats returns current deduplication statistics.
Click to show internal directories.
Click to hide internal directories.