1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-06 16:35:57 +00:00

improvements to the x/client package

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-01-23 00:47:26 +02:00
parent f633ab4b99
commit 4a1f0b6e9e
5 changed files with 157 additions and 4 deletions

View File

@@ -1,6 +1,10 @@
package client
import "time"
import (
"time"
"golang.org/x/time/rate"
)
// All the builtin client options should live here, for easy discovery.
@@ -33,3 +37,12 @@ func PersistentRequestOptions(reqOpts ...RequestOption) Option {
c.PersistentRequestOptions = append(c.PersistentRequestOptions, reqOpts...)
}
}
// RateLimit configures the rate limit for requests.
//
// Defaults to zero which disables rate limiting.
func RateLimit(requestsPerSecond int) Option {
return func(c *Client) {
c.rateLimiter = rate.NewLimiter(rate.Limit(requestsPerSecond), requestsPerSecond)
}
}