https://github.com/snawoot/rlzone
Generic rate limit by key using sliding window algorithm
https://github.com/snawoot/rlzone
Last synced: about 1 month ago
JSON representation
Generic rate limit by key using sliding window algorithm
- Host: GitHub
- URL: https://github.com/snawoot/rlzone
- Owner: Snawoot
- License: mit
- Created: 2023-10-03T20:00:59.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-05T13:34:00.000Z (over 1 year ago)
- Last Synced: 2025-01-26T06:11:15.805Z (3 months ago)
- Language: Go
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rlzone
[](https://godoc.org/github.com/Snawoot/rlzone)
Generic rate limit by key using sliding window algorithm. See Cloudflare blog for details: https://blog.cloudflare.com/counting-things-a-lot-of-different-things/
## Example
```golang
package mainimport (
"fmt"
"log"
"time""github.com/Snawoot/rlzone"
)func main() {
rl, err := rlzone.NewSmallest[string](1*time.Minute, 5)
if err != nil {
log.Fatalf("unable to create ratelimit instance: %v", err)
}
for i := 0; i < 6; i++ {
fmt.Println(rl.Allow("user1"))
}
fmt.Println(rl.Allow("user2"))
// Output:
// true
// true
// true
// true
// true
// false
// true
}
```