http

package
v0.2.4-alpha.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LimiterOnce sync.Once

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

func NewBandwidthLimiter added in v0.2.0

func NewBandwidthLimiter(r rate.Limit, b int)

Types

type APILimiterConfig

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

type BandwidthLimiter added in v0.2.0

type BandwidthLimiter struct {
	Limiter *rate.Limiter
}
var BandwidthLimit *BandwidthLimiter

type BandwidthLimiterConfig added in v0.2.0

type BandwidthLimiterConfig struct {
	Enable bool       //Enable Whether to enable bandwidth limiting
	R      rate.Limit //R The speed at which tokens are generated R per second
	B      int        //B The size of the token bucket
}

type IPLimitConfig added in v0.2.2

type IPLimitConfig struct {
	On         bool   `comment:"optional"`
	RateLimit  int    `comment:"optional"`
	RatePeriod string `comment:"optional"`
}

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 {
	IPLimitCfg  IPLimitConfig
	PathPattern []RateLimiterCell `comment:"optional"`
	HostPattern []RateLimiterCell `comment:"optional"`
	APILimits   []RateLimiterCell `comment:"optional"`
}

Jump to

Keyboard shortcuts

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