Skip to content

Instantly share code, notes, and snippets.

@marciorodrigues87
Last active October 26, 2022 01:43
Show Gist options
  • Save marciorodrigues87/24874313deb77e0329ffaee5cef241f3 to your computer and use it in GitHub Desktop.
Save marciorodrigues87/24874313deb77e0329ffaee5cef241f3 to your computer and use it in GitHub Desktop.
type Repository struct {
apiRateLimitter *rate.Limiter
}
func NewRepository() *Repository {
return &Repository{
apiRateLimitter: rate.NewLimiter(rate.Every(time.Second/time.Duration(config.GetInt("API_RPS"))), 1),
}
}
func (r *Repository) Call(ctx context.Context) error {
if err := r.apiRateLimitter.Wait(ctx); err != nil {
return &retry.RetryableErr{
Err: err,
Detail: "waiting to call",
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment