diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae6c6e1..463a8316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### [13.11.1](https://kaos.sh/ek/13.11.1) + +* `[req]` Make `Limiter` public + ### [13.11.0](https://kaos.sh/ek/13.11.0) * `[req]` Added request limiter diff --git a/req/limiter.go b/req/limiter.go index 210a8142..41f998fc 100644 --- a/req/limiter.go +++ b/req/limiter.go @@ -11,21 +11,21 @@ import "time" // ////////////////////////////////////////////////////////////////////////////////// // -// limiter is request limiter -type limiter struct { +// Limiter is request limiter +type Limiter struct { lastCall time.Time delay time.Duration } // ////////////////////////////////////////////////////////////////////////////////// // -// createLimiter creates new limiter -func createLimiter(rps float64) *limiter { +// NewLimiter creates a new limiter. If rps is less than or equal to 0, it returns nil. +func NewLimiter(rps float64) *Limiter { if rps <= 0 { return nil } - return &limiter{ + return &Limiter{ delay: time.Duration(float64(time.Second) / rps), } } @@ -33,7 +33,7 @@ func createLimiter(rps float64) *limiter { // ////////////////////////////////////////////////////////////////////////////////// // // Wait blocks current goroutine execution until next time slot become available -func (l *limiter) Wait() { +func (l *Limiter) Wait() { if l == nil { return } diff --git a/req/req.go b/req/req.go index b1168d1a..0e4656ca 100644 --- a/req/req.go +++ b/req/req.go @@ -224,7 +224,7 @@ type Engine struct { Transport *http.Transport // Transport is default transport struct Client *http.Client // Client is default client struct - limiter *limiter // Request limiter + limiter *Limiter // Request limiter dialTimeout float64 // dialTimeout is dial timeout in seconds requestTimeout float64 // requestTimeout is request timeout in seconds @@ -437,7 +437,7 @@ func (e *Engine) SetLimit(rps float64) { return } - e.limiter = createLimiter(rps) + e.limiter = NewLimiter(rps) } // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/req/req_test.go b/req/req_test.go index 1ec28a88..8755d766 100644 --- a/req/req_test.go +++ b/req/req_test.go @@ -582,9 +582,9 @@ func (s *ReqSuite) TestQueryEncoding(c *C) { } func (s *ReqSuite) TestLimiter(c *C) { - var l *limiter + var l *Limiter - c.Assert(createLimiter(0.0), IsNil) + c.Assert(NewLimiter(0.0), IsNil) l.Wait() } diff --git a/version.go b/version.go index 21a80d34..a3ceffc2 100644 --- a/version.go +++ b/version.go @@ -8,4 +8,4 @@ package ek // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "13.11.0" +const VERSION = "13.11.1"