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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f583344 · Dec 16, 2023
Dec 16, 2023
Dec 16, 2023
Dec 16, 2023
Dec 16, 2023
Oct 3, 2023
Aug 27, 2023
Sep 15, 2023
Sep 30, 2023
Sep 30, 2023
Aug 27, 2023
Aug 27, 2023
Dec 16, 2023
Dec 2, 2023
Aug 27, 2023
Dec 16, 2023
Dec 16, 2023
Aug 27, 2023
Dec 16, 2023
Dec 16, 2023
Dec 16, 2023
Dec 16, 2023
Dec 15, 2023

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!