summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/throttled/throttled.v2
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/throttled/throttled.v2')
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/.travis.yml18
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/Makefile2
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/README.md83
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/deprecated_test.go4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/doc.go2
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/example_test.go4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/http_test.go2
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/rate.go17
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/rate_test.go4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go6
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go2
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go34
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go (renamed from vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go)4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go2
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go4
-rw-r--r--vendor/gopkg.in/throttled/throttled.v2/varyby_test.go2
17 files changed, 90 insertions, 104 deletions
diff --git a/vendor/gopkg.in/throttled/throttled.v2/.travis.yml b/vendor/gopkg.in/throttled/throttled.v2/.travis.yml
index 29225d7af..0c19e2cd5 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/.travis.yml
+++ b/vendor/gopkg.in/throttled/throttled.v2/.travis.yml
@@ -3,8 +3,13 @@ sudo: false
language: go
go:
- - 1.3
- - tip
+ - 1.7
+ - 1.8
+ - 1.9
+ # 1.x builds the latest in that series. Also try to add other versions here
+ # as they come up so that we're pretty sure that we're maintaining
+ # backwards compatibility.
+ - 1.x
notifications:
email: false
@@ -12,13 +17,6 @@ notifications:
services:
- redis-server
-install:
- - make get-deps
- # Move to the gopkg location that rather than the default clone location
- # otherwise Go 1.4+ complains about incorrect import paths.
- - export GOPKG_DIR=$GOPATH/src/gopkg.in/throttled
- - mkdir -p $GOPKG_DIR
- - mv $TRAVIS_BUILD_DIR $GOPKG_DIR/throttled.v2
- - cd $GOPKG_DIR/throttled.v2
+install: make get-deps
script: make
diff --git a/vendor/gopkg.in/throttled/throttled.v2/Makefile b/vendor/gopkg.in/throttled/throttled.v2/Makefile
index cfc235c31..d6e33c516 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/Makefile
+++ b/vendor/gopkg.in/throttled/throttled.v2/Makefile
@@ -11,9 +11,7 @@ bench:
lint:
gofmt -l .
-ifneq ($(TRAVIS_GO_VERSION),1.3) # go vet doesn't play nicely on 1.3
go vet ./...
-endif
which golint # Fail if golint doesn't exist
-golint . # Don't fail on golint warnings themselves
-golint store # Don't fail on golint warnings themselves
diff --git a/vendor/gopkg.in/throttled/throttled.v2/README.md b/vendor/gopkg.in/throttled/throttled.v2/README.md
index b18dcbcc6..d0e0609a5 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/README.md
+++ b/vendor/gopkg.in/throttled/throttled.v2/README.md
@@ -1,7 +1,7 @@
-# Throttled [![build status](https://secure.travis-ci.org/throttled/throttled.png)](https://travis-ci.org/throttled/throttled) [![GoDoc](https://godoc.org/gopkg.in/throttled/throttled.v2?status.png)](https://godoc.org/gopkg.in/throttled/throttled.v2)
+# Throttled [![build status](https://secure.travis-ci.org/throttled/throttled.svg)](https://travis-ci.org/throttled/throttled) [![GoDoc](https://godoc.org/github.com/throttled/throttled?status.svg)](https://godoc.org/github.com/throttled/throttled)
-Package throttled implements rate limiting access to resources such as
-HTTP endpoints.
+Package throttled implements rate limiting using the [generic cell rate
+algorithm][gcra] to limit access to resources such as HTTP endpoints.
The 2.0.0 release made some major changes to the throttled API. If
this change broke your code in problematic ways or you wish a feature
@@ -11,16 +11,9 @@ what our users need. Thanks!
## Installation
-throttled uses gopkg.in for semantic versioning:
-`go get gopkg.in/throttled/throttled.v2`
-
-As of July 27, 2015, the package is located under its own Github
-organization. Please adjust your imports to
-`gopkg.in/throttled/throttled.v2`.
-
-The 1.x release series is compatible with the original, unversioned
-library written by [Martin Angers][puerkitobio]. There is a
-[blog post explaining that version's usage on 0value.com][blog].
+```sh
+go get -u github.com/throttled/throttled`
+```
## Documentation
@@ -29,57 +22,39 @@ example demonstrates the usage of HTTPLimiter for rate-limiting access
to an http.Handler to 20 requests per path per minute with bursts of
up to 5 additional requests:
- store, err := memstore.New(65536)
- if err != nil {
- log.Fatal(err)
- }
-
- quota := throttled.RateQuota{throttled.PerMin(20), 5}
- rateLimiter, err := throttled.NewGCRARateLimiter(store, quota)
- if err != nil {
- log.Fatal(err)
- }
-
- httpRateLimiter := throttled.HTTPRateLimiter{
- RateLimiter: rateLimiter,
- VaryBy: &throttled.VaryBy{Path: true},
- }
+```go
+store, err := memstore.New(65536)
+if err != nil {
+ log.Fatal(err)
+}
- http.ListenAndServe(":8080", httpRateLimiter.RateLimit(myHandler))
+quota := throttled.RateQuota{throttled.PerMin(20), 5}
+rateLimiter, err := throttled.NewGCRARateLimiter(store, quota)
+if err != nil {
+ log.Fatal(err)
+}
-## Contributing
+httpRateLimiter := throttled.HTTPRateLimiter{
+ RateLimiter: rateLimiter,
+ VaryBy: &throttled.VaryBy{Path: true},
+}
-Since throttled uses gopkg.in for versioning, running `go get` against
-a fork or cloning from Github to the default path will break
-imports. Instead, use the following process for setting up your
-environment and contributing:
-
-```sh
-# Retrieve the source and dependencies.
-go get gopkg.in/throttled/throttled.v2/...
-
-# Fork the project on Github. For all following directions replace
-# <username> with your Github username. Add your fork as a remote.
-cd $GOPATH/src/gopkg.in/throttled/throttled.v2
-git remote add fork git@github.com:<username>/throttled.git
-
-# Create a branch, make your changes, test them and commit.
-git checkout -b my-new-feature
-# <do some work>
-make test
-git commit -a
-git push -u fork my-new-feature
+http.ListenAndServe(":8080", httpRateLimiter.RateLimit(myHandler))
```
-When your changes are ready, [open a pull request][pr] using "compare
-across forks".
+## Related Projects
+
+See [throttled/gcra][throttled-gcra] for a list of other projects related to
+rate limiting and GCRA.
## License
-The [BSD 3-clause license][bsd]. Copyright (c) 2014 Martin Angers and Contributors.
+The [BSD 3-clause license][bsd]. Copyright (c) 2014 Martin Angers and contributors.
[blog]: http://0value.com/throttled--guardian-of-the-web-server
[bsd]: https://opensource.org/licenses/BSD-3-Clause
-[doc]: https://godoc.org/gopkg.in/throttled/throttled.v2
+[doc]: https://godoc.org/github.com/throttled/throttled
+[gcra]: https://en.wikipedia.org/wiki/Generic_cell_rate_algorithm
[puerkitobio]: https://github.com/puerkitobio/
[pr]: https://github.com/throttled/throttled/compare
+[throttled-gcra]: https://github.com/throttled/gcra
diff --git a/vendor/gopkg.in/throttled/throttled.v2/deprecated_test.go b/vendor/gopkg.in/throttled/throttled.v2/deprecated_test.go
index 93406648f..e0453d78f 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/deprecated_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/deprecated_test.go
@@ -5,8 +5,8 @@ import (
"net/http/httptest"
"testing"
- "gopkg.in/throttled/throttled.v2"
- "gopkg.in/throttled/throttled.v2/store"
+ "github.com/throttled/throttled"
+ "github.com/throttled/throttled/store"
)
// Ensure that the current implementation remains compatible with the
diff --git a/vendor/gopkg.in/throttled/throttled.v2/doc.go b/vendor/gopkg.in/throttled/throttled.v2/doc.go
index 302c2bed7..cb14a65a6 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/doc.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/doc.go
@@ -1,3 +1,3 @@
// Package throttled implements rate limiting access to resources such
// as HTTP endpoints.
-package throttled // import "gopkg.in/throttled/throttled.v2"
+package throttled // import "github.com/throttled/throttled"
diff --git a/vendor/gopkg.in/throttled/throttled.v2/example_test.go b/vendor/gopkg.in/throttled/throttled.v2/example_test.go
index 66e6374be..7c4c5df14 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/example_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/example_test.go
@@ -5,8 +5,8 @@ import (
"log"
"net/http"
- "gopkg.in/throttled/throttled.v2"
- "gopkg.in/throttled/throttled.v2/store/memstore"
+ "github.com/throttled/throttled"
+ "github.com/throttled/throttled/store/memstore"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/vendor/gopkg.in/throttled/throttled.v2/http_test.go b/vendor/gopkg.in/throttled/throttled.v2/http_test.go
index 42761da09..52a706e2d 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/http_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/http_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"time"
- "gopkg.in/throttled/throttled.v2"
+ "github.com/throttled/throttled"
)
type stubLimiter struct {
diff --git a/vendor/gopkg.in/throttled/throttled.v2/rate.go b/vendor/gopkg.in/throttled/throttled.v2/rate.go
index 8c11cdb47..649287beb 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/rate.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/rate.go
@@ -84,17 +84,18 @@ type Rate struct {
// RateQuota describes the number of requests allowed per time period.
// MaxRate specified the maximum sustained rate of requests and must
-// be greater than zero. MaxBurst defines the number of requests that
+// be greater than zero. MaxBurst defines the number of requests that
// will be allowed to exceed the rate in a single burst and must be
// greater than or equal to zero.
//
// Rate{PerSec(1), 0} would mean that after each request, no more
-// requests will be permitted for that client for one second. In
-// practice, you probably want to set MaxBurst >0 to provide some
-// flexibility to clients that only need to make a handful of
-// requests. In fact a MaxBurst of zero will *never* permit a request
-// with a quantity greater than one because it will immediately exceed
-// the limit.
+// requests will be permitted for that client for one second.
+// Rate{PerSec(2), 0} permits one request per 0.5 seconds rather than
+// two requests in one second. In practice, you probably want to set
+// MaxBurst >0 to provide some flexibility to clients that only need
+// to make a handful of requests. In fact a MaxBurst of zero will
+// *never* permit a request with a quantity greater than one because
+// it will immediately exceed the limit.
type RateQuota struct {
MaxRate Rate
MaxBurst int
@@ -118,10 +119,12 @@ func PerDay(n int) Rate { return Rate{24 * time.Hour / time.Duration(n), n} }
// as for limiting the number of bytes uploaded.
type GCRARateLimiter struct {
limit int
+
// Think of the DVT as our flexibility:
// How far can you deviate from the nominal equally spaced schedule?
// If you like leaky buckets, think about it as the size of your bucket.
delayVariationTolerance time.Duration
+
// Think of the emission interval as the time between events
// in the nominal equally spaced schedule. If you like leaky buckets,
// think of it as how frequently the bucket leaks one unit.
diff --git a/vendor/gopkg.in/throttled/throttled.v2/rate_test.go b/vendor/gopkg.in/throttled/throttled.v2/rate_test.go
index 292a050bc..a1a5f621e 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/rate_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/rate_test.go
@@ -4,8 +4,8 @@ import (
"testing"
"time"
- "gopkg.in/throttled/throttled.v2"
- "gopkg.in/throttled/throttled.v2/store/memstore"
+ "github.com/throttled/throttled"
+ "github.com/throttled/throttled/store/memstore"
)
const deniedStatus = 429
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go b/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go
index 5476e87ac..0492ba89e 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go
@@ -1,11 +1,11 @@
// Package store contains deprecated aliases for subpackages
-package store // import "gopkg.in/throttled/throttled.v2/store"
+package store // import "github.com/throttled/throttled/store"
import (
"github.com/garyburd/redigo/redis"
- "gopkg.in/throttled/throttled.v2/store/memstore"
- "gopkg.in/throttled/throttled.v2/store/redigostore"
+ "github.com/throttled/throttled/store/memstore"
+ "github.com/throttled/throttled/store/redigostore"
)
// DEPRECATED. NewMemStore is a compatible alias for mem.New
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go
index 5d8fee8b5..352232958 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go
@@ -1,5 +1,5 @@
// Package memstore offers an in-memory store implementation for throttled.
-package memstore // import "gopkg.in/throttled/throttled.v2/store/memstore"
+package memstore // import "github.com/throttled/throttled/store/memstore"
import (
"sync"
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go
index ef003d3de..27b1c9b95 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go
@@ -3,8 +3,8 @@ package memstore_test
import (
"testing"
- "gopkg.in/throttled/throttled.v2/store/memstore"
- "gopkg.in/throttled/throttled.v2/store/storetest"
+ "github.com/throttled/throttled/store/memstore"
+ "github.com/throttled/throttled/store/storetest"
)
func TestMemStoreLRU(t *testing.T) {
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go
index 54208fa6d..03acbcab0 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go
@@ -1,5 +1,5 @@
// Package redigostore offers Redis-based store implementation for throttled using redigo.
-package redigostore // import "gopkg.in/throttled/throttled.v2/store/redigostore"
+package redigostore // import "github.com/throttled/throttled/store/redigostore"
import (
"strings"
@@ -18,11 +18,7 @@ end
if v ~= ARGV[1] then
return 0
end
-if ARGV[3] ~= "0" then
- redis.call('setex', KEYS[1], ARGV[3], ARGV[2])
-else
- redis.call('set', KEYS[1], ARGV[2])
-end
+redis.call('setex', KEYS[1], ARGV[3], ARGV[2])
return 1
`
)
@@ -106,10 +102,17 @@ func (r *RedigoStore) SetIfNotExistsWithTTL(key string, value int64, ttl time.Du
updated := v == 1
- if ttl >= time.Second {
- if _, err := conn.Do("EXPIRE", key, int(ttl.Seconds())); err != nil {
- return updated, err
- }
+ ttlSeconds := int(ttl.Seconds())
+
+ // An `EXPIRE 0` will delete the key immediately, so make sure that we set
+ // expiry for a minimum of one second out so that our results stay in the
+ // store.
+ if ttlSeconds < 1 {
+ ttlSeconds = 1
+ }
+
+ if _, err := conn.Do("EXPIRE", key, ttlSeconds); err != nil {
+ return updated, err
}
return updated, nil
@@ -128,7 +131,16 @@ func (r *RedigoStore) CompareAndSwapWithTTL(key string, old, new int64, ttl time
}
defer conn.Close()
- swapped, err := redis.Bool(conn.Do("EVAL", redisCASScript, 1, key, old, new, int(ttl.Seconds())))
+ ttlSeconds := int(ttl.Seconds())
+
+ // An `EXPIRE 0` will delete the key immediately, so make sure that we set
+ // expiry for a minimum of one second out so that our results stay in the
+ // store.
+ if ttlSeconds < 1 {
+ ttlSeconds = 1
+ }
+
+ swapped, err := redis.Bool(conn.Do("EVAL", redisCASScript, 1, key, old, new, ttlSeconds))
if err != nil {
if strings.Contains(err.Error(), redisCASMissingKey) {
return false, nil
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go
index d47b635d2..ee9e2904d 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go
@@ -6,8 +6,8 @@ import (
"github.com/garyburd/redigo/redis"
- "gopkg.in/throttled/throttled.v2/store/redigostore"
- "gopkg.in/throttled/throttled.v2/store/storetest"
+ "github.com/throttled/throttled/store/redigostore"
+ "github.com/throttled/throttled/store/storetest"
)
const (
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go
index ecfee2638..405c59a12 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go
@@ -1,2 +1,2 @@
// Package storetest provides a helper for testing throttled stores.
-package storetest // import "gopkg.in/throttled/throttled.v2/store/storetest"
+package storetest // import "github.com/throttled/throttled/store/storetest"
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go
index 191b40a4f..2233ebdfb 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go
@@ -1,5 +1,5 @@
// Package storetest provides a helper for testing throttled stores.
-package storetest // import "gopkg.in/throttled/throttled.v2/store/storetest"
+package storetest // import "github.com/throttled/throttled/store/storetest"
import (
"math/rand"
@@ -8,7 +8,7 @@ import (
"testing"
"time"
- "gopkg.in/throttled/throttled.v2"
+ "github.com/throttled/throttled"
)
// TestGCRAStore tests the behavior of a GCRAStore implementation for
diff --git a/vendor/gopkg.in/throttled/throttled.v2/varyby_test.go b/vendor/gopkg.in/throttled/throttled.v2/varyby_test.go
index 66a5f4e98..6ad48ea19 100644
--- a/vendor/gopkg.in/throttled/throttled.v2/varyby_test.go
+++ b/vendor/gopkg.in/throttled/throttled.v2/varyby_test.go
@@ -5,7 +5,7 @@ import (
"net/url"
"testing"
- "gopkg.in/throttled/throttled.v2"
+ "github.com/throttled/throttled"
)
func TestVaryBy(t *testing.T) {