๐Ÿ“ฆ go-chi / httprate-redis

httprate.LimitCounter implementation with Redis backend

โ˜… 37 stars โ‘‚ 11 forks ๐Ÿ‘ 37 watching โš–๏ธ MIT License
๐Ÿ“ฅ Clone https://github.com/go-chi/httprate-redis.git
HTTPS git clone https://github.com/go-chi/httprate-redis.git
SSH git clone git@github.com:go-chi/httprate-redis.git
CLI gh repo clone go-chi/httprate-redis
Namig Aliyev Namig Aliyev Update Config.Client to redis.UniversalClient for Cluster Support (#24) (#26) f9e22d7 7 months ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ _example
๐Ÿ“ .github
๐Ÿ“„ config.go
๐Ÿ“„ go.mod
๐Ÿ“„ go.sum
๐Ÿ“„ httprateredis.go
๐Ÿ“„ LICENSE
๐Ÿ“„ README.md
๐Ÿ“„ README.md

httprate-redis

CI workflow [![GoDoc Widget]][GoDoc]

Redis backend for github.com/go-chi/httprate, implementing httprate.LimitCounter interface.

See example/main.go for usage.

Example

package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"github.com/go-chi/httprate"
	httprateredis "github.com/go-chi/httprate-redis"
)

func main() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)

	r.Use(httprate.Limit(
			5,
			time.Minute,
			httprate.WithKeyByIP(),
			httprateredis.WithRedisLimitCounter(&httprateredis.Config{
				Host: "127.0.0.1", Port: 6379,
			}),
		))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("This is IP rate-limited by 5 req/min"))
	})

	http.ListenAndServe(":3333", r)
}

LICENSE

MIT