Skip to content

Commit

Permalink
refactor: session data locking in middleware/session/data.go
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Sep 13, 2024
1 parent d2cf5b8 commit b479895
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions middleware/session/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func (d *data) Delete(key string) {
//
// keys := d.Keys()
func (d *data) Keys() []string {
d.Lock()
d.RLock()
keys := make([]string, 0, len(d.Data))
for k := range d.Data {
keys = append(keys, k)
}
d.Unlock()
d.RUnlock()
return keys
}

Expand All @@ -117,5 +117,7 @@ func (d *data) Keys() []string {
//
// length := d.Len()
func (d *data) Len() int {
d.RLock()
defer d.RUnlock()
return len(d.Data)
}

0 comments on commit b479895

Please sign in to comment.