volatiletech / abcweb

Go web app framework and generator. Inspired by Rails.
BSD 3-Clause "New" or "Revised" License
265 stars 15 forks source link

Any example about how to use the Session to manage the request validation? #24

Closed rzhang2403 closed 4 years ago

rzhang2403 commented 7 years ago

The abcweb framework is the exact infrastructure that we are looking for in the golang full stack development environment. We are trying to put the RESTful API implementation, like the go-chi/chi style. This can easily work. But, each of API request has to be validated against the authenticated login session. I spotted that several places to enforce the session management:

In the NewRouter(), where creates the application routes, that binds with root := controllers.Root{ Render: a.Render, Session: a.Session, } which implicates the Controller is the place to implement such logic, right? I wonder how to add the session validation with the API processing that defines in the router.Route(...). Any sample codes or application can be real helpful.

Thanks. Nice framework!

-Richard

nullbio commented 6 years ago

Hi @rzhang2403, this is something that is usually accomplished by a middleware, but you could put that logic in the controller. Again though, a middleware is the best place for this sort of validation. This documentation should help you: https://godoc.org/github.com/volatiletech/abcweb/abcmiddleware -- in particular the MiddlewareFunc type.