diff options
author | =Corey Hulen <corey@hulen.com> | 2015-11-23 15:53:48 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-11-23 15:53:48 -0800 |
commit | 4f4cd5e63573da4d6edcc7d4213afaca67c19f88 (patch) | |
tree | cefbc7af53629d97644ca2f6b2369e9d879f0101 /Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go | |
parent | f8a3c9a14edca6df0647d89cf225f2470cbe025c (diff) | |
download | chat-4f4cd5e63573da4d6edcc7d4213afaca67c19f88.tar.gz chat-4f4cd5e63573da4d6edcc7d4213afaca67c19f88.tar.bz2 chat-4f4cd5e63573da4d6edcc7d4213afaca67c19f88.zip |
upgrading libs
Diffstat (limited to 'Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go')
-rw-r--r-- | Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go b/Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go new file mode 100644 index 000000000..760fe2b69 --- /dev/null +++ b/Godeps/_workspace/src/gopkg.in/throttled/throttled.v1/store.go @@ -0,0 +1,31 @@ +package throttled + +import ( + "errors" + "time" +) + +// The error returned if the key does not exist in the Store. +var ErrNoSuchKey = errors.New("throttled: no such key") + +// Store is the interface to implement to store the RateLimit state (number +// of requests per key, time-to-live or creation timestamp). +type Store interface { + // Incr increments the count for the specified key and returns the new value along + // with the number of seconds remaining. It may return an error + // if the operation fails. + // + // The method may return ErrNoSuchKey if the key to increment does not exist, + // in which case Reset will be called to initialize the value. + Incr(string, time.Duration) (int, int, error) + + // Reset resets the key to 1 with the specified window duration. It must create the + // key if it doesn't exist. It returns an error if it fails. + Reset(string, time.Duration) error +} + +// RemainingSeconds is a helper function that returns the number of seconds +// remaining from an absolute timestamp in UTC. +func RemainingSeconds(ts time.Time, window time.Duration) int { + return int((window - time.Now().UTC().Sub(ts)).Seconds()) +} |