Git Product home page Git Product logo

go-ratelimit's Introduction

Build Status

ratelimit

-- import "go-ratelimit/ratelimit"

Usage

type RateLimitConfig

type RateLimitConfig struct {
	Attempts          int
	WindowInSeconds   int
	CooldownInSeconds int
}

RateLimitConfig type for setting rate limiting params

func NewRateLimitConfig

func NewRateLimitConfig(attempts, windowInSeconds, cooldownInSeconds int) *RateLimitConfig

NewRateLimitConfig to create a new config for rate limiting

var ErrBlocked = errors.New("rate limit: blocked")

ErrBlocked is returned when an attribute is rate limited

type RateLimit

type RateLimit struct {
}

RateLimit type for ratelimiting

func NewRateLimit

func NewRateLimit(redisPool *redis.Pool, config *config.RateLimitConfig) *RateLimit

NewRateLimit func to create a new rate limiting type

func (*RateLimit) RateLimitExceeded

func (rl *RateLimit) RateLimitExceeded(key string) bool

RateLimitExceeded returns state of a RateLimit for a key given

func (*RateLimit) Reset

func (rl *RateLimit) Reset(key string) error

Reset func clears the key from rate limiting

func (*RateLimit) Run

func (rl *RateLimit) Run(key string) error

Run initiates ratelimiting for the key given

type RateLimiter

type RateLimiter interface {
	Run(key string) error
	RateLimitExceeded(key string) bool
	Reset(key string) error
}

RateLimiter interface for rate limiting key

go-ratelimit's People

Contributors

guptaabhijit avatar plaguecoder avatar rshetty avatar shishir127 avatar ukriish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ratelimit's Issues

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.