leakybucket
leakybucket copied to clipboard
Missing documentation for real-world use
This library looks exactly what we need. It would be helpful to have guidance on expected usage. For example, if you were to implement IP rate limits or per user limits. It's not clear whether it is ok for the bucket to be request scoped.
Is this correct?
func handleRequest(req app.Request) (app.Response, error) {
bucket, err := storage.Create(req.UserID, 100, time.Minute)
if err != nil {
return nil, InternalError
}
if err := bucket.Add(1); err == ErrorFull {
return nil, ResourceExhausted
} else if err != nil {
return nil, InternalError
}
// handle request
return resp
}
Thanks in advance.
Also, from the implementation it looks like this isn't intended to be used in a distributed environment where multiple instances may be writing to the same bucket.