diff options
author | shen_wen_hui <shenwenhui@zuzuche.com> | 2019-05-05 13:04:31 +0300 |
---|---|---|
committer | shen_wen_hui <shenwenhui@zuzuche.com> | 2019-05-05 13:04:31 +0300 |
commit | 903fdb004a08f8f0952487a2e329aa2373a1bd8c (patch) | |
tree | ac250a19e726e6c0ed94204b02f6f9e130df8e09 | |
parent | 820298e67e38f60df55ebdd80fd8a2b29027beca (diff) | |
parent | aadf35331c6e2b5c6749dc37f7b8b7297101fd54 (diff) |
Merge branch 'master' of https://github.com/admpub/sessions
-rw-r--r-- | sessions.go | 4 | ||||
-rw-r--r-- | store.go | 9 |
2 files changed, 8 insertions, 5 deletions
diff --git a/sessions.go b/sessions.go index 0a318ed..865d952 100644 --- a/sessions.go +++ b/sessions.go @@ -193,8 +193,8 @@ func NewCookie(ctx echo.Context, name, value string) *http.Cookie { } // SetCookie for echo -func SetCookie(ctx echo.Context, key string, value string) { - ctx.SetCookie(key, value) +func SetCookie(ctx echo.Context, key string, value string, args ...interface{}) { + ctx.SetCookie(key, value, args...) } // Error ---------------------------------------------------------------------- @@ -191,12 +191,12 @@ func (s *FilesystemStore) New(ctx echo.Context, name string) (*Session, error) { // Save adds a single session to the response. func (s *FilesystemStore) Save(ctx echo.Context, session *Session) error { - // Delete if max-age is <= 0 - if ctx.CookieOptions().MaxAge <= 0 { + // Delete if max-age is < 0 + if ctx.CookieOptions().MaxAge < 0 { if err := s.erase(session); err != nil { return err } - SetCookie(ctx, session.Name(), "") + SetCookie(ctx, session.Name(), "", -1) return nil } if len(session.ID) == 0 { @@ -220,6 +220,9 @@ func (s *FilesystemStore) Save(ctx echo.Context, // delete session file func (s *FilesystemStore) erase(session *Session) error { + if len(session.ID) == 0 { + return nil + } filename := filepath.Join(s.path, "session_"+session.ID) fileMutex.RLock() defer fileMutex.RUnlock() |