17 lines
416 B
Go
Raw Normal View History

2017-06-16 23:12:28 +00:00
package middleware
import "github.com/aerogo/aero"
2017-06-16 23:25:02 +00:00
// Session middleware saves an existing session if it has been modified.
func Session() aero.Middleware {
2017-06-16 23:12:28 +00:00
return func(ctx *aero.Context, next func()) {
// Handle the request first
next()
// Update session if it has been modified
if ctx.HasSession() && ctx.Session().Modified() {
ctx.App.Sessions.Store.Set(ctx.Session().ID(), ctx.Session())
}
}
}