70 lines
2.7 KiB
Go
70 lines
2.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"galaxy/rtmanager/internal/ports"
|
|
)
|
|
|
|
// Route paths registered by Register. The values match the operation
|
|
// IDs frozen by `rtmanager/api/internal-openapi.yaml` and
|
|
// `rtmanager/contract_openapi_test.go`.
|
|
const (
|
|
listRuntimesPath = "/api/v1/internal/runtimes"
|
|
getRuntimePath = "/api/v1/internal/runtimes/{game_id}"
|
|
startRuntimePath = "/api/v1/internal/runtimes/{game_id}/start"
|
|
stopRuntimePath = "/api/v1/internal/runtimes/{game_id}/stop"
|
|
restartRuntimePath = "/api/v1/internal/runtimes/{game_id}/restart"
|
|
patchRuntimePath = "/api/v1/internal/runtimes/{game_id}/patch"
|
|
cleanupRuntimePath = "/api/v1/internal/runtimes/{game_id}/container"
|
|
)
|
|
|
|
// Dependencies bundles the collaborators required to serve the GM/Admin
|
|
// REST surface. Any service may be nil for tests that exercise a
|
|
// subset of the surface; in that case the unwired routes return
|
|
// `500 internal_error` (mirrors lobby's "service is not wired"
|
|
// pattern).
|
|
type Dependencies struct {
|
|
// Logger receives structured logs scoped per handler. nil falls back
|
|
// to slog.Default.
|
|
Logger *slog.Logger
|
|
|
|
// RuntimeRecords backs the read-only list and get handlers. They do
|
|
// not produce operation_log rows because they do not mutate state.
|
|
RuntimeRecords ports.RuntimeRecordStore
|
|
|
|
// StartRuntime executes the start lifecycle operation. Production
|
|
// wiring passes `*startruntime.Service` (the concrete service
|
|
// satisfies StartService).
|
|
StartRuntime StartService
|
|
|
|
// StopRuntime executes the stop lifecycle operation.
|
|
StopRuntime StopService
|
|
|
|
// RestartRuntime executes the restart lifecycle operation.
|
|
RestartRuntime RestartService
|
|
|
|
// PatchRuntime executes the patch lifecycle operation.
|
|
PatchRuntime PatchService
|
|
|
|
// CleanupContainer executes the cleanup_container lifecycle
|
|
// operation.
|
|
CleanupContainer CleanupService
|
|
}
|
|
|
|
// Register attaches every internal REST route to mux using deps. Each
|
|
// route reads its dependency lazily so a partially-wired Dependencies
|
|
// (e.g., a probe-only listener test) does not crash; missing
|
|
// dependencies surface as `500 internal_error`. Routes use Go 1.22
|
|
// method-aware mux patterns.
|
|
func Register(mux *http.ServeMux, deps Dependencies) {
|
|
mux.HandleFunc("GET "+listRuntimesPath, newListHandler(deps))
|
|
mux.HandleFunc("GET "+getRuntimePath, newGetHandler(deps))
|
|
mux.HandleFunc("POST "+startRuntimePath, newStartHandler(deps))
|
|
mux.HandleFunc("POST "+stopRuntimePath, newStopHandler(deps))
|
|
mux.HandleFunc("POST "+restartRuntimePath, newRestartHandler(deps))
|
|
mux.HandleFunc("POST "+patchRuntimePath, newPatchHandler(deps))
|
|
mux.HandleFunc("DELETE "+cleanupRuntimePath, newCleanupHandler(deps))
|
|
}
|