* 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)
| 223 | ) |
| 224 | */ |
| 225 | func 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 |
| 244 | type RateLimiterMemoryStoreConfig struct { |
no outgoing calls
searching dependent graphs…