Skip to content

Commit

Permalink
use RateLimiter interface instead of x/time/rate
Browse files Browse the repository at this point in the history
  • Loading branch information
SVilgelm committed Sep 29, 2023
1 parent 2587aa4 commit 8c264e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 2 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"
"sync"
"time"

"golang.org/x/time/rate"
)

const (
Expand Down Expand Up @@ -154,7 +152,7 @@ type Client struct {
errorHooks []ErrorHook
invalidHooks []ErrorHook
panicHooks []ErrorHook
rateLimiter *rate.Limiter
rateLimiter RateLimiter
}

// User type is to hold an username and password information
Expand Down Expand Up @@ -925,7 +923,7 @@ func (c *Client) SetOutputDirectory(dirPath string) *Client {

// SetRateLimiter sets an optional `*rate.Limiter`. If set the rate limiter will control
// all requests made with this client.
func (c *Client) SetRateLimiter(rl *rate.Limiter) *Client {
func (c *Client) SetRateLimiter(rl RateLimiter) *Client {
c.rateLimiter = rl
return c
}
Expand Down
7 changes: 0 additions & 7 deletions errors.go

This file was deleted.

11 changes: 11 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package resty

import (
"bytes"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -64,6 +65,16 @@ func (l *logger) output(format string, v ...interface{}) {
l.l.Printf(format, v...)
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Rate Limiter interface
//_______________________________________________________________________

type RateLimiter interface {
Allow() bool
}

var ErrRateLimitExceeded = errors.New("rate limit exceeded")

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Package Helper methods
//_______________________________________________________________________
Expand Down

0 comments on commit 8c264e1

Please sign in to comment.