Documentation
¶
Overview ¶
Package api wires HTTP routes to the instance.Service.
Index ¶
- func NewRouter(svc *instance.Service, jobs store.JobStore, keys *auth.KeyStore, ...) http.Handler
- func WriteError(w http.ResponseWriter, err error)
- func WriteErrorWithDetails(w http.ResponseWriter, err error, details map[string]any)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type BackupView
- type BackupVolumeView
- type ErrorBody
- type JobCanceller
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRouter ¶
func NewRouter(svc *instance.Service, jobs store.JobStore, keys *auth.KeyStore, audit func(http.Handler) http.Handler, metricsHandler http.Handler, canceller JobCanceller, version string) http.Handler
NewRouter builds the full HTTP handler tree. audit is an optional middleware applied around auth-guarded handlers; pass nil for no-op. metricsHandler is an optional handler mounted at GET /metrics; pass nil to omit the endpoint. canceller is an optional JobCanceller for the POST /jobs/{id}/cancel route; pass nil when the job runner is not wired. version is the server's release string (e.g. "v1.0.16", "dev"); included in the /mcp discovery document.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError translates an error into a JSON error response. Sentinel errors from the instance package map to known codes; anything else falls through to "internal".
func WriteErrorWithDetails ¶
func WriteErrorWithDetails(w http.ResponseWriter, err error, details map[string]any)
WriteErrorWithDetails is like WriteError but lets handlers attach structured detail (e.g. host/template/slug).
Types ¶
type BackupView ¶
type BackupView struct {
ID string `json:"id"`
Host string `json:"host"`
Template string `json:"template"`
Slug string `json:"slug"`
State string `json:"state"`
Image string `json:"image,omitempty"`
Volumes []BackupVolumeView `json:"volumes,omitempty"`
Created string `json:"created"`
Finished string `json:"finished,omitempty"`
}
BackupView is the JSON shape of one backup. Manifests are internal verification metadata and are not exposed; per-volume name+size are.
type BackupVolumeView ¶
BackupVolumeView is one exported volume's public metadata: name + tar size.
type ErrorBody ¶
type ErrorBody struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
ErrorBody is the JSON shape of every error response.
type JobCanceller ¶
JobCanceller cancels an in-flight (running) job. Implemented by *jobs.Runner. Nil when the job runner is not wired (no -state-db), in which case the cancel endpoint is unreachable anyway (the jobs-disabled guard precedes it).