• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Redis-backed rate limiter in Go

speedbump GoDoc

A Redis-backed Rate Limiter for Go

wercker status

Cool stuff

  • Backed by Redis, so it keeps track of requests across a cluster
  • Extensible timing functions. Includes defaults for tracking requests per second, minute, and hour
  • Works with IPv4, IPv6, or any other unique identifier
  • Example middleware included for Gin (See: ginbump) and Negroni (See: negronibump)

Versions

Branch Go Get Command Client Version -
v2 go get gopkg.in/etcinit/speedbump.v2 gopkg.in/redis.v5 Link
v1, master go get gopkg.in/etcinit/speedbump.v1 gopkg.in/redis.v3 Link
v0 go get gopkg.in/etcinit/speedbump.v0 gopkg.in/redis.v2 Link

Usage

  • Get a working Redis server
  • Go get:
$ go get github.com/etcinit/speedbump
  • Include it in your code
package main

import (
	"fmt"
	"time"

	"github.com/etcinit/speedbump"
	"gopkg.in/redis.v5"
)

func main() {
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
		DB:       0,
	})
	hasher := speedbump.PerSecondHasher{}

	// Here we create a limiter that will only allow 5 requests per second
	limiter := speedbump.NewLimiter(client, hasher, 5)

	for {
		// This example has a hardcoded IP, but you would replace it with the IP
		// of a client on a real case.
		success, err := limiter.Attempt("127.0.0.1")

		if err != nil {
			panic(err)
		}

		if success {
			fmt.Println("Successful!")
		} else {
			fmt.Println("Limited! :(")
		}

		time.Sleep(time.Millisecond * time.Duration(100))
	}
}
  • Output:
Successful!
Successful!
Successful!
Successful!
Successful!
Successful!
Limited! :(
Limited! :(
Limited! :(
Limited! :(
Limited! :(
Successful!
Successful!
Successful!
Successful!
Successful!
Successful!
Limited! :(
Limited! :(
Limited! :(
Limited! :(
Successful!
Successful!
...

More Repositories

1

phabulous

A Phabricator bot for Slack
Go
218
star
2

enclosure

Javascript IOC Container and module loading system
JavaScript
7
star
3

ensure

Ensure.js: A simple library for checking types in Javascript + extras
CSS
7
star
4

vertex

A barebones Docker image with essentials for PHP developement and deployment
Shell
6
star
5

craze

A micro-library for racing HTTP GET requests
Haskell
4
star
6

central

Go implementation of the backend of etcinit/nexus
Go
3
star
7

minebot

Minecraft Bot for my final AI project
JavaScript
3
star
8

sauron

CLI tool for tail-ing a whole log directory recursively and dynamically
Go
2
star
9

dotfiles

Neovim + others configuration files
Vim Script
2
star
10

tutum-php

Partial Tutum PHP client
PHP
2
star
11

docker-haskell-stack

Docker image with stack
2
star
12

structures

A small experiment on data structures on PHP
PHP
1
star
13

saltstack

Stack for setting up personal environments
SaltStack
1
star
14

mockingbird

A DSL for mocking dependencies on PHP unit tests
PHP
1
star
15

kawaii

[Read-Only Mirror] Some utilities for serving Hakyll sites/blogs
Haskell
1
star
16

nexus-client-go

Golang client for the Nexus Configuration Server
Go
1
star
17

nexus-harvester

Log harvester for the Nexus Configuration Server
JavaScript
1
star
18

nexii

Nexus Configuration Server CLI client
Go
1
star
19

phabricator-yubikey

Experimental integration of Yubikey OTPs with Phabricator
PHP
1
star
20

shift

A changelog generator
Haskell
1
star
21

etcinit

Config files for my GitHub profile.
1
star
22

blog

[READ-ONLY] Mirror of https://phabricator.chromabits.com/diffusion/B/
CSS
1
star
23

laravel-tutum

Experimental Laravel integration with Tutum's API
PHP
1
star
24

nexus

Configuration file server
JavaScript
1
star
25

xss-challenge

XSS challenge over IRC, because why not
JavaScript
1
star
26

CSCI4050-CarRentalService

Simple car rental project for UGA's CSCI4050 class
Java
1
star
27

radio

Broadcast messages to multiple Go channels
Go
1
star
28

flow-redux-example

A simple To Do app built using Redux and checked with Flow
JavaScript
1
star
29

UGAACM-GameDev

This repository contains the first game project of the game development group of the University of Georgia chapter of the ACM
Java
1
star
30

jenkins-php-slave-docker

Docker image of Jenkins node with PHP
1
star
31

ohmygorm

Some helpers for Gorm using Confer
Go
1
star