http

package
v0.1.3-test-2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIP

func GetIP(r *http.Request) string

GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.

func Limit

func Limit(next http.Handler) http.Handler

func NewAPILimiter

func NewAPILimiter(cfg *APILimiterConfig) error

Types

type APILimiterConfig

type APILimiterConfig struct {
	HTTPLimitCfg HTTPLimitConfig
	PathPattern  map[string]MemoryLimiterConfig
	APILimits    map[string]MemoryLimiterConfig // routePrefix-apiName  =>  limit config
	HostPattern  map[string]MemoryLimiterConfig
}

type HTTPLimitConfig

type HTTPLimitConfig struct {
	On         bool
	RateLimit  int
	RatePeriod string
}

type MemoryLimiterConfig

type MemoryLimiterConfig struct {
	RateLimit  int    // rate
	RatePeriod string // per period
}

type RateLimiterCell

type RateLimiterCell struct {
	Key        string
	RateLimit  int
	RatePeriod string
}

type RateLimiterConfig

type RateLimiterConfig struct {
	HTTPLimitCfg HTTPLimitConfig
	PathPattern  []RateLimiterCell
	HostPattern  []RateLimiterCell
	APILimits    []RateLimiterCell
}

Jump to

Keyboard shortcuts

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