feat: add diagnostic interview loop

This commit is contained in:
user
2026-04-26 16:24:35 +09:00
parent 0e232ff405
commit 4a4240fea2
21 changed files with 926 additions and 23 deletions

View File

@@ -0,0 +1,62 @@
package interview
import (
"errors"
"sync"
)
var ErrSessionNotFound = errors.New("diagnostic session not found")
type Store interface {
Create(Session) (Session, error)
Get(string) (Session, error)
Update(Session) (Session, error)
}
type MemoryStore struct {
mu sync.RWMutex
sessions map[string]Session
}
func NewMemoryStore() *MemoryStore {
return &MemoryStore{
sessions: make(map[string]Session),
}
}
func (s *MemoryStore) Create(session Session) (Session, error) {
s.mu.Lock()
defer s.mu.Unlock()
s.sessions[session.ID] = cloneSession(session)
return session, nil
}
func (s *MemoryStore) Get(id string) (Session, error) {
s.mu.RLock()
defer s.mu.RUnlock()
session, ok := s.sessions[id]
if !ok {
return Session{}, ErrSessionNotFound
}
return cloneSession(session), nil
}
func (s *MemoryStore) Update(session Session) (Session, error) {
s.mu.Lock()
defer s.mu.Unlock()
if _, ok := s.sessions[session.ID]; !ok {
return Session{}, ErrSessionNotFound
}
s.sessions[session.ID] = cloneSession(session)
return session, nil
}
func cloneSession(session Session) Session {
session.Stack = append([]string(nil), session.Stack...)
session.Questions = append([]Question(nil), session.Questions...)
session.Answers = append([]Answer(nil), session.Answers...)
return session
}