Add rate limiter
This commit is contained in:
17
pkg/http/rate_limiter.go
Normal file
17
pkg/http/rate_limiter.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package http
|
||||
|
||||
import "time"
|
||||
|
||||
type RateLimiter struct {
|
||||
ticker *time.Ticker
|
||||
}
|
||||
|
||||
func NewRateLimiter(apiRateLimitPerSecond int) *RateLimiter {
|
||||
return &RateLimiter{
|
||||
ticker: time.NewTicker(time.Second / time.Duration(apiRateLimitPerSecond)),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RateLimiter) Wait() {
|
||||
<-r.ticker.C
|
||||
}
|
||||
Reference in New Issue
Block a user