Skip to content

Commit

Permalink
SetMulti session method added.
Browse files Browse the repository at this point in the history
now instead of setting session values individually,
a map of session values can be set on a shot
  • Loading branch information
joicemjoseph authored and Joice M. Joseph committed Jun 8, 2021
1 parent 7c19a70 commit 4a8df93
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ func (s *Session) Set(key string, val interface{}) error {
return s.manager.store.Set(s, s.cookie.Value, key, val)
}

// SetMulti sets all values in the session.
// Its up to store to commit all previously
// set values at once or store it on each set.
func (s *Session) SetMulti(values map[string]interface{}) error {
// Check if session is set before accessing it
if !s.isSet {
return ErrInvalidSession
}

for k, v := range values {
if err := s.manager.store.Set(s, s.cookie.Value, k, v); err != nil {
return err
}
}

return nil
}

// Commit commits all set to store. Its up to store to commit
// all previously set values at once or store it on each set.
func (s *Session) Commit() error {
Expand Down

0 comments on commit 4a8df93

Please sign in to comment.