From 18a9096684ab0b1468a08d442d38b7b675d94810 Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Sun, 28 Jul 2024 19:32:33 +0300 Subject: Session middleware --- session/memstore.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 session/memstore.go (limited to 'session/memstore.go') diff --git a/session/memstore.go b/session/memstore.go new file mode 100644 index 0000000..97d70a1 --- /dev/null +++ b/session/memstore.go @@ -0,0 +1,25 @@ +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 +} -- cgit v1.2.3