Skip to content
/ rl Public

rl is a rate limit middleware for multiple limit rules.

License

Notifications You must be signed in to change notification settings

2manymws/rl

Repository files navigation

rl Go Reference build Coverage Code to Test Ratio Test Execution Time

rl is a rate limit middleware for multiple limit rules.

Usage

Prepare an instance that implements rl.Limiter interface.

Then, generate the middleware ( func(next http.Handler) http.Handler ) with rl.New

package main

import (
    "log"
    "net/http"

    "github.com/2manymws/rl"
)

func main() {
    r := http.NewServeMux()
    r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello World"))
    })

    var l rl.Limiter = newMyLimiter()
    m := rl.New(l)

    log.Fatal(http.ListenAndServe(":8080", m(r)))
}

Rate limiting approach

rl uses the Sliding Window Counter pattern same as go-chi/httprate.

Reference

  • go-chi/httprate
    • Most of rl's rate limit implementations refer to httprate. Thanks for the simple and clean implementation!