From 40632a83495f3b01138b959f774e8d2554b92d86 Mon Sep 17 00:00:00 2001 From: rizzOn Date: Fri, 5 Jun 2026 22:15:19 +0530 Subject: [PATCH] day 3: of trying to rizzzzzzz my gophy mol --- in_memory_sesssion_store.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 in_memory_sesssion_store.go diff --git a/in_memory_sesssion_store.go b/in_memory_sesssion_store.go new file mode 100644 index 0000000..9cc120b --- /dev/null +++ b/in_memory_sesssion_store.go @@ -0,0 +1,35 @@ +package gopherriz + +import ( + "sync" + "time" +) + +type Session struct { + UserId string + ExpiresAt time.Time +} + +type SessionManager struct { + mu sync.RWMutex + sessions map[string]Session +} + +func (s *SessionManager) Get(key string) (Session, bool) { + s.mu.RLock() + val, ok := s.sessions[key] + s.mu.RUnlock() + + if !ok || time.Now().After(val.ExpiresAt) { + return Session{}, false + } + + return val, ok + +} + +func (s *SessionManager) Set(session Session, key string) { + s.mu.Lock() + s.sessions[key] = session + s.mu.Unlock() +}