Skip to content

Commit 895121d

Browse files
authored
Fix rate limiter docs (#2366)
* Improve wording for the comment of Burst * Improve rate limiter docs
1 parent abecadc commit 895121d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

middleware/rate_limiter.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type (
155155
RateLimiterMemoryStore struct {
156156
visitors map[string]*Visitor
157157
mutex sync.Mutex
158-
rate rate.Limit //for more info check out Limiter docs - https://pkg.go.dev/golang.org/x/time/rate#Limit.
158+
rate rate.Limit // for more info check out Limiter docs - https://pkg.go.dev/golang.org/x/time/rate#Limit.
159159

160160
burst int
161161
expiresIn time.Duration
@@ -170,15 +170,16 @@ type (
170170

171171
/*
172172
NewRateLimiterMemoryStore returns an instance of RateLimiterMemoryStore with
173-
the provided rate (as req/s). The provided rate less than 1 will be treated as zero.
173+
the provided rate (as req/s).
174174
for more info check out Limiter docs - https://pkg.go.dev/golang.org/x/time/rate#Limit.
175175
176176
Burst and ExpiresIn will be set to default values.
177177
178+
Note that if the provided rate is a float number and Burst is zero, Burst will be treated as the rounded down value of the rate.
179+
178180
Example (with 20 requests/sec):
179181
180182
limiterStore := middleware.NewRateLimiterMemoryStore(20)
181-
182183
*/
183184
func NewRateLimiterMemoryStore(rate rate.Limit) (store *RateLimiterMemoryStore) {
184185
return NewRateLimiterMemoryStoreWithConfig(RateLimiterMemoryStoreConfig{
@@ -188,7 +189,7 @@ func NewRateLimiterMemoryStore(rate rate.Limit) (store *RateLimiterMemoryStore)
188189

189190
/*
190191
NewRateLimiterMemoryStoreWithConfig returns an instance of RateLimiterMemoryStore
191-
with the provided configuration. Rate must be provided. Burst will be set to the value of
192+
with the provided configuration. Rate must be provided. Burst will be set to the rounded down value of
192193
the configured rate if not provided or set to 0.
193194
194195
The build-in memory store is usually capable for modest loads. For higher loads other
@@ -225,7 +226,7 @@ func NewRateLimiterMemoryStoreWithConfig(config RateLimiterMemoryStoreConfig) (s
225226
// RateLimiterMemoryStoreConfig represents configuration for RateLimiterMemoryStore
226227
type RateLimiterMemoryStoreConfig struct {
227228
Rate rate.Limit // Rate of requests allowed to pass as req/s. For more info check out Limiter docs - https://pkg.go.dev/golang.org/x/time/rate#Limit.
228-
Burst int // Burst additionally allows a number of requests to pass when rate limit is reached
229+
Burst int // Burst is maximum number of requests to pass at the same moment. It additionally allows a number of requests to pass when rate limit is reached.
229230
ExpiresIn time.Duration // ExpiresIn is the duration after that a rate limiter is cleaned up
230231
}
231232

0 commit comments

Comments
 (0)