Help us shape the future of Go! Take the 2026 Go Developer Survey

api

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0, AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package api is Headmesh's public REST API (OpenAPI 3.1, RFC 9457 errors), a thin layer over package service.

Every operation either declares the "bearer" security requirement — enforced by middleware, which turns the API key into a service.Principal — or is on the short public allowlist (device enrollment, which carries its own one-time credentials). TestEveryOperationIsAuthenticatedOrAllowlisted keeps it that way.

Index

Constants

This section is empty.

Variables

View Source
var PublicOperations = map[string]bool{"enroll": true, "complete-enrollment": true}

PublicOperations are reachable without an API key.

Functions

func Health

func Health(router chi.Router, st *store.Store, rec *Recovery)

Health mounts /healthz (process up) and /readyz (database reachable and not recovering) on router.

func New

func New(router chi.Router, opt Options) huma.API

New registers every operation on router and returns the Huma API (for the OpenAPI document).

Types

type Options

type Options struct {
	Service *service.Service
	Logger  *slog.Logger
	// TrustForwardedFor makes the API take the client address from X-Forwarded-For (set by Caddy). Enable only
	// when every request arrives through the trusted proxy.
	TrustForwardedFor bool
	// EnrollPerMinute limits enrollment calls per client address (default 30).
	EnrollPerMinute int
	Version         string
}

Options configure the API.

type Recovery

type Recovery struct {
	// contains filtered or unexported fields
}

Recovery gates the API while a restored control plane catches up (plan §13.4): /readyz answers 503 and every request that could change state gets 503 with Retry-After, until End is called. Reads keep working, so operators can inspect grants and audit while cells catch up. The zero value (and a nil *Recovery) is open.

func (*Recovery) Active

func (r *Recovery) Active() bool

Active reports whether the gate is closed.

func (*Recovery) Begin

func (r *Recovery) Begin()

Begin closes the gate.

func (*Recovery) End

func (r *Recovery) End()

End opens the gate.

func (*Recovery) Middleware

func (r *Recovery) Middleware(next http.Handler) http.Handler

Middleware refuses state-changing requests while recovery is active.

Jump to

Keyboard shortcuts

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