Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing documentation for real-world use #38

Open
dpup opened this issue Jul 30, 2020 · 1 comment
Open

Missing documentation for real-world use #38

dpup opened this issue Jul 30, 2020 · 1 comment

Comments

@dpup
Copy link

dpup commented Jul 30, 2020

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.

@dpup
Copy link
Author

dpup commented Jul 31, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant