Code Monkey home page Code Monkey logo

goralim's Introduction

banner

Goralim

goralim is a Golang package that provides a rate limiter based on Token bucket algorithm. It is capabale to handle distributed workload with its redis database support. It has HTTP server middleware support (as of now).

๐Ÿšง this is a beta version now and under active development. For production use, fork it and made changes based on your need.

Install

go get "github.com/0verread/goralim" -m

Usage

import (
  goralim "github.com/0verread/goralim"
)

	// Redis initialization
	config := goralim.RedisConfig {
		HOST: "127.0.0.1",
		PORT: 6379,
    // password
		PASS: "",
	}
	redisStore := goralim.NewRedisClient(config)

	// setup rate limiter for a key (key can be userId/client)
	// 10 is bucket size, 5 is bucket refill rate per second
	tb := goralim.NewTokenBucket("key123", redisStore, 10, 5)

	// create HTTP server and setup a goralim middleware to put a rate limiter
	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "Hey There this is a Request")
	})

	rateLimitedHandler := goralim.RateLimiter(tb, handler)
	http.ListenAndServe(":8080", rateLimitedHandler)

License

Under MIT license

goralim's People

Contributors

0verread 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.