RateStor is a simple, efficient, and thread-safe rate-limiting library for Go. It allows you to limit the rate of requests. The library provides a flexible way to define different limits for different keys.
To install ratestor
, use the go get
command:
go get github.com/ksysoev/ratestor
package main
import (
"fmt"
"time"
"github.com/ksysoev/ratestor"
)
func main () {
stor := ratestor.NewRateStor()
defer stor.Close()
err := stor.Allow("user1_min", 1*time.Minute, 100)
if err == ratestor.ErrRateLimitExceeded {
fmt.Println("Minute limit is exceded")
}
err := stor.Allow("user1_10min", 10*time.Minute, 300)
if err == ratestor.ErrRateLimitExceeded {
fmt.Println("10 Minute limit is exceded")
}
}
Contributions to Wasabi are welcome! Please submit a pull request or create an issue to contribute.
This project is licensed under the MIT License - see the LICENSE.md file for details.