update
This commit is contained in:
parent
838d7bfd95
commit
2e13a9f710
1 changed files with 5 additions and 13 deletions
18
store.go
18
store.go
|
@ -159,12 +159,12 @@ var fileMutex sync.RWMutex
|
||||||
// it will use os.TempDir().
|
// it will use os.TempDir().
|
||||||
//
|
//
|
||||||
// See NewCookieStore() for a description of the other parameters.
|
// See NewCookieStore() for a description of the other parameters.
|
||||||
func NewFilesystemStore(path string) *FilesystemStore {
|
func NewFilesystemStore(path string, keyPairs ...[]byte) *FilesystemStore {
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
path = os.TempDir()
|
path = os.TempDir()
|
||||||
}
|
}
|
||||||
fs := &FilesystemStore{
|
fs := &FilesystemStore{
|
||||||
Codecs: []securecookie.Codec{securecookie.NewLiteCodec()},
|
Codecs: securecookie.CodecsFromPairs(keyPairs...),
|
||||||
path: path,
|
path: path,
|
||||||
}
|
}
|
||||||
return fs
|
return fs
|
||||||
|
@ -291,15 +291,14 @@ func (s *FilesystemStore) MaxAge(age int) {
|
||||||
|
|
||||||
// save writes encoded session.Values to a file.
|
// save writes encoded session.Values to a file.
|
||||||
func (s *FilesystemStore) save(session *Session) error {
|
func (s *FilesystemStore) save(session *Session) error {
|
||||||
encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
|
b, err := securecookie.Gob.Serialize(session.Values)
|
||||||
s.Codecs...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
filename := filepath.Join(s.path, "session_"+session.ID)
|
filename := filepath.Join(s.path, "session_"+session.ID)
|
||||||
fileMutex.Lock()
|
fileMutex.Lock()
|
||||||
defer fileMutex.Unlock()
|
defer fileMutex.Unlock()
|
||||||
return os.WriteFile(filename, []byte(encoded), 0600)
|
return os.WriteFile(filename, b, 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load reads a file and decodes its content into session.Values.
|
// load reads a file and decodes its content into session.Values.
|
||||||
|
@ -311,14 +310,7 @@ func (s *FilesystemStore) load(ctx echo.Context, session *Session) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = securecookie.DecodeMultiWithMaxAge(
|
return securecookie.Gob.Deserialize(fdata, &session.Values)
|
||||||
session.Name(), string(fdata),
|
|
||||||
&session.Values,
|
|
||||||
ctx.CookieOptions().MaxAge,
|
|
||||||
s.Codecs...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FilesystemStore) DeleteExpired(maxAge float64) error {
|
func (s *FilesystemStore) DeleteExpired(maxAge float64) error {
|
||||||
|
|
Loading…
Reference in a new issue