✏ move mutex

pull/1038/head
Fenny 2020-11-26 22:16:49 +01:00
parent 450bf14c3d
commit a0442be8b6
2 changed files with 5 additions and 5 deletions

View File

@ -11,7 +11,7 @@ import (
)
type Session struct {
// sync.RWMutex
sync.Mutex
id string // session id
fresh bool // if new session
ctx *fiber.Ctx // fiber context
@ -129,9 +129,9 @@ func (s *Session) Save() error {
}
// Convert data to bytes
mux.Lock()
s.Lock()
data := gotiny.Marshal(&s.data)
mux.Unlock()
s.Unlock()
// pass raw bytes with session id to provider
if err := s.config.Storage.Set(s.id, data, s.config.Expiration); err != nil {

View File

@ -54,9 +54,9 @@ func (s *Store) Get(c *fiber.Ctx) (*Session, error) {
raw, err := s.Storage.Get(id)
// Unmashal if we found data
if err == nil {
mux.Lock()
sess.Lock()
gotiny.Unmarshal(raw, &sess.data)
mux.Unlock()
sess.Unlock()
sess.fresh = false
} else if raw != nil && err.Error() != "key does not exist" {
return nil, err