Skip to content

Simple middleware to rate-limit HTTP requests.

License

Notifications You must be signed in to change notification settings

rv-openshift/tollbooth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc license

Tollbooth

This is a generic middleware to rate limit HTTP requests.

Usage

package main

import (
    "github.com/didip/tollbooth"
    "github.com/didip/tollbooth/storages"
    "net/http"
    "time"
)

func HelloHandler(w http.ResponseWriter, req *http.Request) {
    w.Write([]byte("Hello, World!"))
}

func main() {
    // 1. Create a request limiter storage.
    storage := storages.NewInMemory()

    // 2. Create a request limiter per handler.
    http.Handle("/", tollbooth.LimitByIPFuncHandler(storage, tollbooth.NewRequestLimit(1, time.Second), HelloHandler))
    http.ListenAndServe(":12345", nil)
}

About

Simple middleware to rate-limit HTTP requests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%