Stewart Webb
Stewart Webb

Reputation: 189

Golang middleware authentication depending on route

I am building an API in Go. I handle all authentication by including a secret token in the header. I have added some middleware using negroni that picks this out of the header and checks the database to see if it exists.

This is fine but now I want to do permissions based upon the route in question. I have a table in a database with permissions for only some routes etc and I would like to use this logic in the middleware so that the handlers never need to worry about it.

My problem is that the middleware needs to know what handler is being called so that it can check for the correct record in the database. What is the best way to pass or extract the current route / handler using negroni?

Thanks

Upvotes: 0

Views: 1099

Answers (0)

Related Questions