day 3: of trying to rizzzzzzz my gophy mol

This commit is contained in:
rizzOn 2026-06-05 22:15:19 +05:30
parent 815dc130d6
commit 40632a8349
1 changed files with 35 additions and 0 deletions

View File

@ -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()
}