Documentation ¶
Index ¶
- Constants
- Variables
- func GetIP(r *http.Request) string
- func Limit(domain string) func(http.Handler) http.Handler
- func NewAPILimiter(cfg *APILimiterConfig) error
- func NewBandwidthLimiter(r rate.Limit, b int)
- type APILimiterConfig
- type BandwidthLimiter
- type BandwidthLimiterConfig
- type IPLimitConfig
- type KeyToRateLimiterNameCell
- type MemoryLimiterConfig
- type RateLimiterConfig
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 ¶
GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.
func NewAPILimiter ¶
func NewAPILimiter(cfg *APILimiterConfig) error
func NewBandwidthLimiter ¶ added in v0.2.0
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
var BandwidthLimit *BandwidthLimiter
type BandwidthLimiterConfig ¶ added in v0.2.0
type IPLimitConfig ¶ added in v0.2.2
type KeyToRateLimiterNameCell ¶ added in v1.0.1
type MemoryLimiterConfig ¶
type RateLimiterConfig ¶
type RateLimiterConfig struct { IPLimitCfg IPLimitConfig PathPattern []KeyToRateLimiterNameCell `comment:"optional"` HostPattern []KeyToRateLimiterNameCell `comment:"optional"` APILimits []KeyToRateLimiterNameCell `comment:"optional"` NameToLimit []MemoryLimiterConfig `comment:"optional"` }
Click to show internal directories.
Click to hide internal directories.