mirror of https://github.com/gofiber/fiber.git
✏ move mutex
parent
450bf14c3d
commit
a0442be8b6
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue