MCPcopy
hub / github.com/labstack/echo / NewRateLimiterMemoryStoreWithConfig

Function NewRateLimiterMemoryStoreWithConfig

middleware/rate_limiter.go:225–241  ·  view source on GitHub ↗

* NewRateLimiterMemoryStoreWithConfig returns an instance of RateLimiterMemoryStore with the provided configuration. Rate must be provided. Burst will be set to the rounded up value of the configured rate if not provided or set to 0. The built-in memory store is usually capable for modest loads. Fo

(config RateLimiterMemoryStoreConfig)

Source from the content-addressed store, hash-verified

223 )
224*/
225func NewRateLimiterMemoryStoreWithConfig(config RateLimiterMemoryStoreConfig) (store *RateLimiterMemoryStore) {
226 store = &RateLimiterMemoryStore{}
227
228 store.rate = config.Rate
229 store.burst = config.Burst
230 store.expiresIn = config.ExpiresIn
231 if config.ExpiresIn == 0 {
232 store.expiresIn = DefaultRateLimiterMemoryStoreConfig.ExpiresIn
233 }
234 if config.Burst == 0 {
235 store.burst = int(math.Max(1, math.Ceil(float64(config.Rate))))
236 }
237 store.visitors = make(map[string]*Visitor)
238 store.timeNow = time.Now
239 store.lastCleanup = store.timeNow()
240 return
241}
242
243// RateLimiterMemoryStoreConfig represents configuration for RateLimiterMemoryStore
244type RateLimiterMemoryStoreConfig struct {

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…