Giter VIP home page Giter VIP logo

ratelimiter's Introduction

ratelimiter

"No running in the API!"

Go based ratelimiter with redis backend

GoDoc Go Report Card

Usage

Using redis caching

pool := &redis.Pool{ ... }

limiter := NewRateLimiter(pool, logger)

// Decrement and get current limit
exceeded, remaining, reset, err := limiter.Limit(identity, limit, window)

// Just fetch current remaining limit
remaining, reset, err := limiter.QueryLimit(identity, limit, window)

Input

  • identity - (string) a unique string to identify the user for which you're ratelimiting
  • limit - (int) number of requests allowable within window
  • window - (time.Duration) length of the window

Output

  • exceeded - (boolean) true if rate limit has been exceeded
  • remaining - (int) number of requests still allowable in current window
  • reset - (time.Duration) length of time until window resets

With in-memory fake caching (nb Doesn't perform actual rate limiting. Provides a simulation for testing and novelty purposes)

limiter := NewRateLimiter(logger)

exceeded, remaining, reset, err := limiter.Limit(identity, limit, window)
remaining, reset, err := limiter.QueryLimit(identity, limit, window)

Unlimited limits

There are of course times when you want a user to not be subject to ratelimiting. You could just bypass the call to Limit, but that's needless work on your behalf. Instead, just set the limit to -1:

exceeded, remaining, reset, err := limiter.Limit("MyIdentity", -1, 0)

ratelimiter's People

Contributors

necrophonic avatar ian-kent avatar emead avatar

Watchers

rasputnik avatar Karim Lawani avatar James Cloos avatar Andrew Maddaford avatar Chris Morgan avatar Jimmy avatar Carl Allen avatar Lloyd Griffiths avatar Nigel Hamilton avatar Mario Paolucci avatar  avatar  avatar John Shields avatar Osvaldo Martini avatar  avatar MArk Williams avatar Filip Lisowski avatar  avatar Michael Woods avatar  avatar  avatar  avatar Simon Rowe avatar  avatar  avatar Sameer Srivastava avatar  avatar Matthew O'Reilly avatar  avatar  avatar  avatar  avatar  avatar Dan Falconer avatar  avatar Szymon Ramczykowski avatar Simon Readman avatar  avatar Michael Acreman avatar  avatar  avatar Matt Stone avatar  avatar  avatar Craig Baldwin avatar  avatar Peadar Kelly avatar Nawazish Ali avatar stefano basile avatar Richard Etherington avatar Anthony Borisade avatar  avatar jsimons avatar  avatar  avatar  avatar Joel Clemence avatar  avatar  avatar  avatar Mike Williams avatar Natalie Blanchette avatar  avatar  avatar  avatar Divya avatar  avatar  avatar Liam Hutton avatar  avatar Adrian Cho avatar  avatar Raziel J Lowe avatar  avatar Steve Roberts avatar

Forkers

uk-gov-mirror

ratelimiter's Issues

In Memory should actually limit

Initial implementation of in memory rate limiter always returns "not limited". For an actual release it would be good if this actually implemented at least a pseudo-real rate limiter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.