feat: scaffold codespace backend

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-02 15:07:54 +08:00
co-authored by Claude Fable 5
commit 411ed1f8ba
43 changed files with 4428 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package service
import (
"codespace/internal/process"
"codespace/internal/workspace"
)
// WorkspaceService orchestrates workspace lifecycle operations.
type WorkspaceService struct {
workspaces workspace.Manager
processes process.Manager
}
// NewWorkspaceService creates a WorkspaceService.
func NewWorkspaceService(workspaces workspace.Manager, processes process.Manager) *WorkspaceService {
return &WorkspaceService{workspaces: workspaces, processes: processes}
}
// Create creates a new workspace.
func (s *WorkspaceService) Create(id string) (*workspace.Workspace, error) {
return s.workspaces.Create(id)
}
// Get retrieves a workspace by id.
func (s *WorkspaceService) Get(id string) (*workspace.Workspace, error) {
return s.workspaces.Get(id)
}
// Delete stops any running process for the workspace, then removes it.
func (s *WorkspaceService) Delete(id string) error {
status := s.processes.Status(id)
if status.Running {
_ = s.processes.Stop(id)
}
return s.workspaces.Delete(id)
}