middleware

package module
v0.0.0-...-7fd3dc1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

echo-idempotency

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIdempotencyConfig = IdempotencyConfig{
	Skipper:   middleware.DefaultSkipper,
	Methods:   []string{http.MethodPost},
	KeyLookup: "header:X-Idempotency-Key",
	TTL:       24 * time.Hour,
}

Functions

func Idempotency

func Idempotency() echo.MiddlewareFunc

func IdempotencyWithConfig

func IdempotencyWithConfig(config IdempotencyConfig) echo.MiddlewareFunc

Types

type IdempotencyConfig

type IdempotencyConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper middleware.Skipper

	Rediser Rediser

	// Methods defines a list of HTTP methods that should be works as idempotent.
	// Optional. Default value []string{"POST"}.
	Methods []string `yaml:"methods"`

	// KeyLookup is a string in the form of "<source>:<name>" that is used
	// to extract key from the request.
	// Optional. Default value "header:X-Idempotency-Key".
	// Possible values:
	// - "header:<name>"
	// - "query:<name>"
	// - "form:<name>"
	KeyLookup string `yaml:"key_lookup"`

	KeyLookupFunc KeyExtractor

	TTL time.Duration
}

IdempotencyConfig defines the config for Idempotency middleware.

type KeyExtractor

type KeyExtractor func(echo.Context) (string, bool, error)

type Rediser

type Rediser interface {
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
}

type ReqRecord

type ReqRecord struct {
	Done            bool                `json:"done"`
	ResponseCode    int                 `json:"response_code"`
	ResponseHeaders map[string][]string `json:"response_headers"`
	ResponseBody    []byte              `json:"response_body"`
}

ReqRecord ...

Jump to

Keyboard shortcuts

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