api

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package api wires HTTP routes to the instance.Service.

Index

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) 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.

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).

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON writes v as JSON with the given status.

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

type BackupVolumeView struct {
	Name      string `json:"name"`
	SizeBytes int64  `json:"size_bytes"`
}

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

type JobCanceller interface {
	Cancel(id string) bool
}

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL