middlewares

package
v1.0.1-beta-4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT, Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authentication

func Authentication(next http.Handler) http.Handler

Authentication is middleware that provides JWT authentication.

func BasicAuth

func BasicAuth(expectedUsername, expectedPassword string) func(http.Handler) http.Handler

BasicAuth is middleware that checks the expected username and password match the http basic auth values.

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. A "chain-address" was detected (i.e: via a signed SIWE). 2. If 1. isn't present, it will use an existing X-Forwarded-For IP included by a load-balancer in the infrastructure. 3. If 2. 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 (
	// ContextKeyAddress is used to store the address of the client for the incoming request.
	ContextKeyAddress ContextKey = iota
	// ContextKeyChainID is used to store the chain id of the client for the incoming request.
	ContextKeyChainID ContextKey = iota
	// ContextIPAddress is used to store the ip address of the client for the incoming request.
	ContextIPAddress ContextKey = iota
)

type RateLimiterConfig

type RateLimiterConfig struct {
	Default RateLimiterRouteConfig

	JSONRPCRoute        string
	JSONRPCMethodLimits map[string]RateLimiterRouteConfig
}

RateLimiterConfig specifies a default rate limiting configuration, and optional custom rate limiting rules for a JSON RPC sub-route with path JSONRPCRoute. i.e: particular JSON RPC methods can have different rate limiting.

type RateLimiterRouteConfig

type RateLimiterRouteConfig struct {
	MaxRPI   uint64
	Interval time.Duration
}

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