From 2916082d5ed94ef86ad58bdb7256ae07b214c4f3 Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Mon, 29 Jul 2024 02:38:17 +0300 Subject: Начальный коммит MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/session/memstore.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 middleware/session/memstore.go (limited to 'middleware/session/memstore.go') diff --git a/middleware/session/memstore.go b/middleware/session/memstore.go new file mode 100644 index 0000000..2fcef39 --- /dev/null +++ b/middleware/session/memstore.go @@ -0,0 +1,31 @@ +package session + +import ( + "context" + "sync" +) + +type MemoryStore struct { + store sync.Map +} + +func (s *MemoryStore) Load(ctx context.Context, sessionID string) Value { + val, ok := s.store.Load(sessionID) + if ok { + return val.(Value) + } + + return Value{} +} + +func (s *MemoryStore) Save(ctx context.Context, sessionID string, value Value) error { + s.store.Store(sessionID, value) + + return nil +} + +func (s *MemoryStore) Remove(ctx context.Context, sessionID string) error { + s.store.Delete(sessionID) + + return nil +} -- cgit v1.2.3