1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-24 04:15:56 +00:00

sessions: add OnDestroy event, relative to: https://github.com/kataras/iris/issues/969

Former-commit-id: de9ad83a663f44d62dbb7520595cacb21a7f694a
This commit is contained in:
Gerasimos Maropoulos
2018-04-22 14:13:40 +03:00
parent 6862501f7f
commit 06c17bc8bb
2 changed files with 36 additions and 5 deletions

View File

@@ -107,6 +107,20 @@ func (s *Sessions) UpdateExpiration(ctx context.Context, expires time.Duration)
}
}
// DestroyListener is the form of a destroy listener.
// Look `OnDestroy` for more.
type DestroyListener func(sid string)
// OnDestroy registers one or more destroy listeners.
// A destroy listener is fired when a session has been removed entirely from the server (the entry) and client-side (the cookie).
// Note that if a destroy listener is blocking, then the session manager will delay respectfully,
// use a goroutine inside the listener to avoid that behavior.
func (s *Sessions) OnDestroy(listeners ...DestroyListener) {
for _, ln := range listeners {
s.provider.registerDestroyListener(ln)
}
}
// Destroy remove the session data and remove the associated cookie.
func (s *Sessions) Destroy(ctx context.Context) {
cookieValue := GetCookie(ctx, s.config.Cookie)