From 4a8df936ac37ca5cd1e198f95360586ceab2d1f8 Mon Sep 17 00:00:00 2001 From: Joice Joseph Date: Tue, 8 Jun 2021 16:46:19 +0530 Subject: [PATCH] SetMulti session method added. now instead of setting session values individually, a map of session values can be set on a shot --- session.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/session.go b/session.go index 0ea0b50..6ab7d07 100644 --- a/session.go +++ b/session.go @@ -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 {