updated stuff

This commit is contained in:
2026-01-23 19:07:05 +11:00
parent c14c5d43ee
commit b810b75011
33 changed files with 1186 additions and 222 deletions

46
internal/session/store.go Normal file
View File

@@ -0,0 +1,46 @@
package session
import (
"crypto/rand"
"encoding/base64"
"sync"
"time"
)
type Store struct {
sessions sync.Map
cleanup *time.Ticker
}
func NewStore() *Store {
s := &Store{
cleanup: time.NewTicker(1 * time.Minute),
}
// Background cleanup of expired sessions
go func() {
for range s.cleanup.C {
s.cleanupExpired()
}
}()
return s
}
func (s *Store) Delete(id string) {
s.sessions.Delete(id)
}
func (s *Store) cleanupExpired() {
s.sessions.Range(func(key, value any) bool {
session := value.(*RegistrationSession)
if time.Now().After(session.ExpiresAt) {
s.sessions.Delete(key)
}
return true
})
}
func generateID() string {
b := make([]byte, 32)
rand.Read(b)
return base64.RawURLEncoding.EncodeToString(b)
}