Skip to content

ksysoev/ratestor

Repository files navigation

RateStor: A Go Rate Limiting Library

RateStor codecov License: MIT

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.

Installation

To install ratestor, use the go get command:

go get github.com/ksysoev/ratestor

Usage

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")
    }
}

Contributing

Contributions to Wasabi are welcome! Please submit a pull request or create an issue to contribute.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.