http

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Middleware      = "Middleware"
	MethodSeparator = "-"
)

Variables

View Source
var (
	ErrTooManyRequest = gfsperrors.Register(Middleware, http.StatusTooManyRequests, 960001, "too many requests, please try it again later")
)
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(domain string) func(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
	PathSequence []string
	APILimits    map[string][]MemoryLimiterConfig // routePrefix-apiName  =>  limit config
	HostPattern  map[string][]MemoryLimiterConfig
	HostSequence []string
}

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 KeyToRateLimiterNameCell added in v1.0.1

type KeyToRateLimiterNameCell struct {
	Key    string
	Method string
	Names  []string
}

type MemoryLimiterConfig

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

type RateLimiterConfig

type RateLimiterConfig struct {
	IPLimitCfg  IPLimitConfig
	PathPattern []KeyToRateLimiterNameCell `comment:"optional"`
	HostPattern []KeyToRateLimiterNameCell `comment:"optional"`
	APILimits   []KeyToRateLimiterNameCell `comment:"optional"`
	NameToLimit []MemoryLimiterConfig      `comment:"optional"`
}

Jump to

Keyboard shortcuts

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