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

api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: AGPL-3.0 Imports: 55 Imported by: 0

Documentation

Overview

Package api is Zoomies' HTTP surface: the REST API described by api/openapi.yaml, the Server-Sent Events streams the UI lives on, the Prometheus endpoint, the GitHub webhook receiver, and the embedded operator UI.

Everything here is transport. Decisions about the fleet belong to internal/controller, authorisation policy to internal/auth and SQL to internal/store; a handler in this package reads a request, asks one of those three, and renders the answer in the shape the OpenAPI document promises. Keeping it that thin is what makes the contract checkable: the surface can be walked route by route in a test, and nothing behind it has an opinion about HTTP.

Index

Constants

View Source
const SessionCookie = "zoomies_session"

SessionCookie is the name of the cookie a browser session lives in. It is exported because the OpenAPI document names it and the CLI's browser-login helper has to read it back.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(ctx context.Context) string

clientIP returns the address a request came from, resolved through the proxies the operator has said to trust.

func Identity

func Identity(ctx context.Context) *auth.Identity

Identity returns the authenticated caller, or nil on an unauthenticated route. Handlers use it for audit attribution and for the checks that depend on who is asking rather than on the route alone.

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the identifier this request is logged under, which is what an internal error hands back so an operator can find the log line.

Types

type Options

type Options struct {
	// Controller is the running control plane. Required.
	Controller *controller.Controller
	// Logger is the process logger; nil uses slog's default.
	Logger *slog.Logger
	// StreamHeartbeat is how often a live stream sends a keep-alive and
	// re-checks the credential it was opened with. Zero uses the shipped
	// interval; a test sets it small so it does not have to wait one.
	StreamHeartbeat time.Duration
}

Options are what the API needs to serve. Everything else it uses -- the store, the auth service, the event bus, the configuration -- it takes from the controller, so there is exactly one wiring of those and no way for the API to end up talking to a different database than the fleet does.

type Server

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

Server is the HTTP surface. Build it with New and either hand Handler() to a listener of your own or let ListenAndServe run one.

func New

func New(opts Options) (*Server, error)

New builds the server. It does no I/O beyond loading the encryption key and, when single sign-on is configured, discovering the identity provider.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the whole surface: API, webhook, metrics and UI. It is safe to serve from a listener of the caller's own, which is what the tests and the installer's health check do.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

ListenAndServe serves until ctx is cancelled, then shuts down gracefully.

It returns nil on a clean shutdown; anything else is a failure worth exiting on. The listener is opened before the readiness notification is sent, so a service manager that starts a dependent unit on READY=1 is not racing the bind.

Jump to

Keyboard shortcuts

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