idempotent

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// HeaderKey is the HTTP header key used to stored idempotency keys
	HeaderKey = "X-Idempotency-Key"
)

Variables

View Source
var (
	// ErrSeenBefore is returned when our http ResponseWriter has seen the idempotency key before
	ErrSeenBefore = errors.New("X-Idempotency-Key seen before")
)

Functions

func FromRequest

func FromRequest(req *http.Request, rec Recorder) (key string, seen bool)

FromRequest extracts the idempotency key from HTTP headers and records its presence in the provided Recorder.

A nil Recorder will always return idempotency keys as unseen.

func Header(r *http.Request) string

Header returns the idempotency key from a http.Request headers

func SeenBefore

func SeenBefore(w http.ResponseWriter)

SeenBefore sets a HTTP response code as an error for previously seen idempotency keys.

Types

type Recorder

type Recorder interface {
	SeenBefore(key string) bool
}

Recorder offers a method to determine if a given key has been seen before or not. Each invocation of SeenBefore needs to record each key found, but there's no minimum duration required.

Directories

Path Synopsis
Package lru is a simple inmemory Recorder implementation.
Package lru is a simple inmemory Recorder implementation.

Jump to

Keyboard shortcuts

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