Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayzhan211/dcard-middleware
simple ratelimiter in golang (using Redis)
https://github.com/jayzhan211/dcard-middleware
Last synced: about 1 month ago
JSON representation
simple ratelimiter in golang (using Redis)
- Host: GitHub
- URL: https://github.com/jayzhan211/dcard-middleware
- Owner: jayzhan211
- Created: 2021-02-07T01:10:51.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-20T07:48:29.000Z (almost 4 years ago)
- Last Synced: 2023-03-08T20:36:51.342Z (almost 2 years ago)
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Usage
1. Run Redis Server (port: 6379)
2. Run main.go
Configuration
* useMem(Bool): set if you dont use Redis
* ipLimit(Int): rate limit for certain IP
* duration(time.Duration): time for rate limiting, reset after timeout
3. Run client request
* `curl -I 127.0.0.1:8080/hello`
* `curl -H "X-Forwarded-For: 1.2.5.4:8080" -I 127.0.0.1:8080/hello`## Example
`go run main.go -duration 1s -ipLimit 2`![](https://i.imgur.com/R2zeoWi.png)
# dcard-middleware
Rate Limiting
1000 times in an hour for each IP address
response `X-RateLimit-Remaining` (remains time to visit) and `X-RateLimit-Reset` (time to reset)- [X] count client visiting counts
- [X] add timeout for each IP address
- [X] add get/remove test (mem)
- [X] add get/remove test (Redis)
- [X] add Redis Ring (test only)
- [ ] use `PXAT` if `alicebob/miniredis` is available for redis v6.2
- [ ] add `atomic` for mem# QA
## Why use Redis, instead of golang map?
`INCR` and `EXPIRE` are useful
> ref: https://redislabs.com/redis-best-practices/basic-rate-limiting/