rl
is a rate limit middleware for multiple limit rules.
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)))
}
rl
uses the Sliding Window Counter pattern same as go-chi/httprate.
- https://blog.cloudflare.com/counting-things-a-lot-of-different-things/
- https://www.figma.com/blog/an-alternative-approach-to-rate-limiting/
- go-chi/httprate
- Most of
rl
's rate limit implementations refer to httprate. Thanks for the simple and clean implementation!
- Most of