limiter-examples icon indicating copy to clipboard operation
limiter-examples copied to clipboard

Great work! Question...

Open hiqsociety opened this issue 5 years ago • 3 comments

Operating a website hosting service and would like to rate limit by domain name for bandwidth. e.g. 200kbps per domain name.

possible to do this using limiter? i'm using fasthttp

hiqsociety avatar Oct 30 '20 19:10 hiqsociety

possible to adjust the throttling rate on the fly dynamically? how to do this?

gitmko0 avatar Oct 30 '20 20:10 gitmko0

@hiqsociety Yes there is a middleware for fasthttp, you can find an example here: https://github.com/ulule/limiter-examples/blob/master/fasthttp/main.go

novln avatar Nov 03 '20 14:11 novln

@gitmko0 Yes you can, but you'll have to create some plumbing and boilerplate to do so.

In summary, create a new instance of limiter with the new rate (https://github.com/ulule/limiter/blob/545607961466ac04a70680947ce0f0e7fbb2366f/limiter.go#L31)

And pass this new instance to the service / middleware / components managing the rate limiter, by replacing the previous instance and this new one.

novln avatar Nov 03 '20 14:11 novln