didip/tollbooth

Limit by Context value

Mathiou04 opened this issue · 3 comments

Hey there and thanks for this package!

I am currently trying to do some "user specific rate limiting" but using the BasicAuth mechanism doesn't work as the authentication mechanism I use is JWT.

At the moment, my workaround is to use a middleware that:

  • parses the JWT
  • extract the informations I need from it
  • add a new header to the request that I can then use to decide on the rate limiting

I am not sure that adding a header to a request like this is a very good practice and I think it would be cleaner to add the extracted informations to the request's context.

Do you have an opinion about this? What do you think of adding methods SetContextValue, RemoveContextValue to the library?

I can open a PR if you think it is an idea worth integrating.

didip commented

Ah, tollbooth was created before context existed, if you would like to create a PR, I’d love to see it.

Ok great then.
Do you think I should pop a new Limiter attribute (contextValues) or use a single map[string]*gocache.Cache struct?

didip commented

new limiter attribute will make it consistent to the rest of the codebase, don't you think?