1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-06 03:27:27 +00:00

Fix up for sessions

- Restore expiration state of the sessions
- Add APIs to modify expire date
- Free the timer for the session destroy task

Former-commit-id: 4d796a9efba2c37cd3750275ac62c068ceb82be8
This commit is contained in:
corebreaker
2017-07-31 21:49:30 +03:00
parent 4f2985cb4e
commit 0f1a265e5a
5 changed files with 226 additions and 91 deletions

View File

@@ -27,6 +27,8 @@ type (
flashes map[string]*flashMessage
mu sync.RWMutex
createdAt time.Time
expireAt *time.Time // nil pointer means no expire date
timer *time.Timer
provider *provider
}
@@ -42,6 +44,22 @@ func (s *Session) ID() string {
return s.sid
}
// HasExpireDate test if this session has an expire date, if not, this session never expires
func (s *Session) HasExpireDate() bool {
return s.expireAt != nil
}
// GetExpireDate get the expire date, if this session has no expire date, the returned value has the zero value
func (s *Session) GetExpireDate() time.Time {
var res time.Time
if s.expireAt != nil {
res = *s.expireAt
}
return res
}
// Get returns a value based on its "key".
func (s *Session) Get(key string) interface{} {
s.mu.RLock()
@@ -322,7 +340,7 @@ func (s *Session) Delete(key string) bool {
}
func (s *Session) updateDatabases() {
s.provider.updateDatabases(s.sid, s.values)
s.provider.updateDatabases(s, s.values)
}
// DeleteFlash removes a flash message by its key.