Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

🔬 Redis support for the chi-ratelimit library.

License

Notifications You must be signed in to change notification settings

noel-archive/chi-ratelimit-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔬 chi-ratelimit-redis

Implements Redis support for chi-ratelimit

Why is this its own separate package?

I wanted to keep chi-ratelimit without any dependencies, so this was the only solution. If only Go had support for peer-dependencies like NPM. 🥺

Example

$ go get github.com/noelware/chi-ratelimit/redis
package main

import (
	"net/http"
	"github.com/go-chi/chi/v5"
	"github.com/noelware/chi-ratelimit"
)

func main() {
	ratelimiter := ratelimiter.NewRatelimiter(
		ratelimiter.WithProvider(redis.New(
			redis.WithKeyPrefix("owo:"),
			redis.WithClient(<redis client here>),
		)),
	)
	
	router := chi.NewRouter()
	router.Use(ratelimiter.Middleware)
	router.Get("/", func (w http.ResponseWriter, req *http.Request) {
		// do stuff here
	})
	
	http.ListenAndServe(":3030", router)
}

License

chi-ratelimit-redis is released under the MIT License by Noelware.