Skip to content

httprate.LimitCounter implementation with Redis backend

License

Notifications You must be signed in to change notification settings

go-chi/httprate-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e32a97d · Mar 29, 2025

History

26 Commits
Aug 8, 2024
Mar 29, 2025
Aug 25, 2022
Aug 8, 2024
Oct 29, 2024
Mar 29, 2025
Mar 29, 2025
Oct 29, 2024
Oct 23, 2024
Oct 23, 2024

Repository files navigation

httprate-redis

CI workflow GoDoc Widget

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

About

httprate.LimitCounter implementation with Redis backend

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages