Skip to content

Commit

Permalink
Fix race condition in request
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Jul 13, 2018
1 parent b062fd2 commit 69acf88
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions exchanges/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var supportedMethods = []string{"GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS
// Requester struct for the request client
type Requester struct {
HTTPClient *http.Client
UnauthLimit RateLimit
AuthLimit RateLimit
UnauthLimit *RateLimit
AuthLimit *RateLimit
Name string
Cycle time.Time
m sync.Mutex
Expand All @@ -34,8 +34,8 @@ type RateLimit struct {
}

// NewRateLimit creates a new RateLimit
func NewRateLimit(d time.Duration, rate int) RateLimit {
return RateLimit{Duration: d, Rate: rate}
func NewRateLimit(d time.Duration, rate int) *RateLimit {
return &RateLimit{Duration: d, Rate: rate}
}

// ToString returns the rate limiter in string notation
Expand Down Expand Up @@ -156,17 +156,21 @@ func (r *Requester) SetRateLimit(auth bool, duration time.Duration, rate int) {
}

// GetRateLimit gets the request Requester ratelimiter
func (r *Requester) GetRateLimit(auth bool) RateLimit {
func (r *Requester) GetRateLimit(auth bool) *RateLimit {
if auth {
return r.AuthLimit
}
return r.UnauthLimit
}

// New returns a new Requester
func New(name string, authLimit, unauthLimit RateLimit, httpRequester *http.Client) *Requester {
r := &Requester{HTTPClient: httpRequester, UnauthLimit: unauthLimit, AuthLimit: authLimit, Name: name}
return r
func New(name string, authLimit, unauthLimit *RateLimit, httpRequester *http.Client) *Requester {
return &Requester{
HTTPClient: httpRequester,
UnauthLimit: unauthLimit,
AuthLimit: authLimit,
Name: name,
}
}

// IsValidMethod returns whether the supplied method is supported
Expand Down

0 comments on commit 69acf88

Please sign in to comment.