feat: add supervisor prototype with embedded frontend

This commit is contained in:
root
2026-03-09 19:15:53 +01:00
parent 96c4ce1697
commit 84de557052
56 changed files with 4044 additions and 10 deletions

View File

@ -0,0 +1,51 @@
package memory
import (
"context"
"sort"
"supervisor/internal/domain"
"sync"
)
type Store struct {
mu sync.RWMutex
sessions map[string]domain.Session
}
func NewStore() *Store {
return &Store{sessions: make(map[string]domain.Session)}
}
func (s *Store) Upsert(_ context.Context, session domain.Session) error {
s.mu.Lock()
defer s.mu.Unlock()
s.sessions[session.ID] = session
return nil
}
func (s *Store) Get(_ context.Context, id string) (domain.Session, bool, error) {
s.mu.RLock()
defer s.mu.RUnlock()
session, ok := s.sessions[id]
return session, ok, nil
}
func (s *Store) List(_ context.Context) ([]domain.Session, error) {
s.mu.RLock()
defer s.mu.RUnlock()
items := make([]domain.Session, 0, len(s.sessions))
for _, session := range s.sessions {
items = append(items, session)
}
sort.Slice(items, func(i, j int) bool {
return items[i].CreatedAt.After(items[j].CreatedAt)
})
return items, nil
}
func (s *Store) Delete(_ context.Context, id string) error {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.sessions, id)
return nil
}