GithubHelp home page GithubHelp logo

rate-limiting's Introduction

Rate limiting

Rate-limiting module that stops a particular requestor for Go using Redis.

When the limit has been reached, return a 429 error.

The application is configured by default with the strategy "Fixed Window" per IP.

Run the application

  • docker installed
  • docker-compose up

Run the application locally

Requirements

  • go installed
  • docker installed
  • start redis ./script.sh (port 6380)

Start the application

Default: FixedWindow

  • export REDIS_ADDRESS=localhost:6380
  • go run .

Start with SlidingWindowLogs:

  • export REDIS_ADDRESS=localhost:6380
  • export RATE_LIMITER_NAME=SlidingWindowLogs
  • go run .

Test locally

  • go test ./... -v

Integration test

  • go test ./... -tags=integration

Example

GET http://localhost:8080/

After too many requests:

Body

Rate limit exceeded. Try again in 24 seconds.

Headers

HTTP/1.1 429 Too Many Requests
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
X-Rate-Limit-Limit: 5
X-Rate-Limit-Remaining: -1
X-Rate-Limit-Reset: 19
Date: Sun, 06 Sep 2020 05:10:41 GMT
Content-Length: 46

Flush Redis cache

  • docker exec -it rate-app-redis redis-cli
  • FLUSHALL

Access Go logs in Docker

  • docker logs rate-app-go

Rebuild docker image

  • docker-compose build

rate-limiting's People

Contributors

pjserol avatar

Watchers

 avatar

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.