middlewares

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT, Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(next http.Handler) http.Handler

CORS sets the correct headers for allowing cross origin requests.

func OtelHTTP

func OtelHTTP(operation string) func(h http.Handler) http.Handler

OtelHTTP wraps the handler h with OTEL metrics.

func RESTChainID

func RESTChainID(acceptedChainIDs []tableland.ChainID) func(next http.Handler) http.Handler

RESTChainID adds to the request context the {chainID} that must be present in the REST path.

func RateLimitController

func RateLimitController(cfg RateLimiterConfig) (mux.MiddlewareFunc, error)

RateLimitController creates a new middleware to rate limit requests. It applies a priority based rate limiting key for the rate limiting: 1. If found, use an existing X-Forwarded-For IP included by a load-balancer in the infrastructure. 2. If 1. isn't present, it will use the connection remote address.

func TraceID

func TraceID(next http.Handler) http.Handler

TraceID creates a trace id for tracing. Every log goes with a trace id and it is also returned as a HTTP header.

func WithLogging

func WithLogging(h http.Handler) http.Handler

WithLogging logs requests and responses that contain useful information.

Types

type ContextKey

type ContextKey int

ContextKey is used to key context values.

const (
	// ContextKeyChainID is used to store the chain id of the client for the incoming request,
	// this is found in the request path.
	ContextKeyChainID ContextKey = iota
	// ContextIPAddress is used to store the ip address of the client for the incoming request,
	// this is found in either the request IP or the x-forwarded header.
	ContextIPAddress ContextKey = iota
)

type RateLimiterConfig

type RateLimiterConfig struct {
	Default RateLimiterRouteConfig
}

RateLimiterConfig specifies a default rate limiting configuration.

type RateLimiterRouteConfig

type RateLimiterRouteConfig struct {
	MaxRPI   uint64
	Interval time.Duration
	APIKey   string
}

RateLimiterRouteConfig specifies the maximum request per interval, and interval length for a rate limiting rule.

Jump to

Keyboard shortcuts

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