idempotency

package module
v0.0.0-...-3e124c7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 9 Imported by: 0

README

idempotency

IMPORTANT: This package is still under development process. Basic test cases are covered but API is not stable yet.

Middleware to make idempotent HTTP handlers.

Documentation

Index

Constants

View Source
const (
	DefaultIdempotencyKeyHeader = "Idempotency-Key"
	DefaultLockDuration         = 10 * time.Second
)
View Source
const (
	RecoveryPointStart = "start"
)

Variables

This section is empty.

Functions

func New

func New(config Config) func(http.Handler) http.Handler

func RecoveryPoint

func RecoveryPoint(name string, r *http.Request, fn func() string)

Types

type Config

type Config struct {
	Locker               Locker
	Repository           Repository
	IdempotencyKeyHeader string
}

type IdempotencyKey

type IdempotencyKey struct {
	Key                string
	RecoveryPoint      string
	RequestMethod      string
	RequestURLPath     string
	RequestURLRawQuery string
	RequestHeaders     http.Header
	RequestBodyHash    string
	ResponseStatusCode int
	ResponseHeaders    http.Header
	ResponseBody       string
}

type Locker

type Locker interface {
	Lock(key string) bool
	Unlock(key string)
}

type Repository

type Repository interface {
	// GetOrInsertKey returns the key if it exists, or inserts it if it doesn't.
	// If the key is inserted, the returned bool is true.
	GetOrInsert(*IdempotencyKey) (*IdempotencyKey, bool, error)
	// SetRecoveryPoint sets the recovery point for the key.
	SetRecoveryPoint(key string, recoveryPoint string) error
	// SetResponse sets the response fields for the key.
	SetResponse(key string, statusCode int, headers http.Header, body string) error
}

Jump to

Keyboard shortcuts

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