summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshen_wen_hui <shenwenhui@zuzuche.com>2019-05-05 13:04:31 +0300
committershen_wen_hui <shenwenhui@zuzuche.com>2019-05-05 13:04:31 +0300
commit903fdb004a08f8f0952487a2e329aa2373a1bd8c (patch)
treeac250a19e726e6c0ed94204b02f6f9e130df8e09
parent820298e67e38f60df55ebdd80fd8a2b29027beca (diff)
parentaadf35331c6e2b5c6749dc37f7b8b7297101fd54 (diff)
Merge branch 'master' of https://github.com/admpub/sessions
-rw-r--r--sessions.go4
-rw-r--r--store.go9
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 ----------------------------------------------------------------------
diff --git a/store.go b/store.go
index 0641254..cdce23e 100644
--- a/store.go
+++ b/store.go
@@ -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()