api

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package api exposes Brevis's HTTP interface.

It uses plain net/http. ServeMux's method-and-path routing (Go 1.22+) covers what is needed, and the rule is to avoid a framework when the stdlib does the job. This system's hard work is in the queue, in the scheduler and in the state machine — not in the HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions added in v0.7.0

type Actions interface {
	Toggle(ctx context.Context, slug string) (bool, error)
	Disparar(ctx context.Context, slug string, now time.Time, params map[string]string) (uuid.UUID, error)
}

Actions are the two effects the screen triggers. A small interface on purpose: the UI must not be able to do anything more to the system than pause a schedule and ask for a run now.

type AlertsReader added in v0.8.0

type AlertsReader interface {
	ForRun(ctx context.Context, runID uuid.UUID) ([]alerts.Record, error)
}

AlertsReader lists a run's alerts. It is a CONSTRUCTOR argument and not a settable field, so that forgetting to wire it is a compile error rather than a screen that quietly stops showing alerts. Two features shipped switched off in one week because nothing outside a test ever set the field they needed.

nil is still allowed, for a process that renders no pages.

type Checker

type Checker interface {
	Check(ctx context.Context) error
}

Checker is a dependency readiness consults. A small interface on purpose (rule 5): postgres.Pool already satisfies it with no adapter.

type Definitions added in v0.7.0

type Definitions interface {
	Definition(ctx context.Context, slug string) (wf.Workflow, error)
}

Definitions reads a workflow's published definition. Kept apart from `Leitura` because it returns the domain, not a screen projection.

type Leitura

type Leitura interface {
	Indicators(ctx context.Context, window time.Duration) (postgres.Indicators, error)
	IndicatorsFor(ctx context.Context, window time.Duration, workflow string) (postgres.Indicators, error)
	RunsPerDay(ctx context.Context, workflow string, days int) ([]postgres.Day, error)
	LoadTrend(ctx context.Context, workflow string, days int) ([]postgres.LoadDay, error)
	RunsPerHour(ctx context.Context, horas int) ([]postgres.Bucket, error)
	InFlight(ctx context.Context, limite int) ([]postgres.RunSummary, error)
	LatestRuns(ctx context.Context, limite int) ([]postgres.RunSummary, error)
	Runs(ctx context.Context, f postgres.RunFilter) ([]postgres.RunSummary, error)
	CountRuns(ctx context.Context, f postgres.RunFilter) (int, error)
	WorkflowRuns(ctx context.Context, slug string, limite int) ([]postgres.RunSummary, error)
	Workflows(ctx context.Context) ([]postgres.WorkflowSummary, error)
	Schedules(ctx context.Context) ([]postgres.ScheduleSummary, error)
	Projects(ctx context.Context) ([]postgres.ProjectSummary, error)
	QueueDepth(ctx context.Context) (int, int, error)
}

Leitura is what the UI needs from the database. The interface is declared here, in the consumer.

type RunsChart added in v0.7.0

type RunsChart interface {
	Get(ctx context.Context, id uuid.UUID) (run.Run, error)
	NodeStates(ctx context.Context, id uuid.UUID) (map[string]postgres.NodeState, error)
	LogsDaRun(ctx context.Context, id uuid.UUID) ([]postgres.StepLog, error)
}

RunsChart reads a Run and the state of its steps.

type Server

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

Server carries the router and the dependencies readiness consults.

func NewServer

func NewServer(log *slog.Logger, checkers map[string]Checker, ui *UI) *Server

NewServer builds the router. The checkers are named so that /ready says WHICH dependency failed, and not merely that something did.

`ui` may be nil: a process that only serves health checks does not need the pages, and requiring them would couple the server to the database for no reason.

func NewServerAutenticado

func NewServerAutenticado(log *slog.Logger, checkers map[string]Checker, ui *UI,
	cred auth.Credential, inseguro bool,
) *Server

NewServerAutenticado is the same, requiring a session when the credential is configured. `inseguro` sends the cookie without the Secure flag — needed only for plain http in development, because a Secure cookie never comes back over http and the login would look simply broken.

func (*Server) HTTPServer

func (s *Server) HTTPServer(addr string) *http.Server

HTTPServer returns the configured server. The timeouts exist because net/http's default is none: without them, a slow connection holds a handler indefinitely.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP makes Server an http.Handler, with an access log.

type UI

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

UI registers the server-rendered pages and the JSON the React island consumes.

func NewUI

func NewUI(l Leitura, d Definitions, e RunsChart, a Actions, al AlertsReader,
	m branding.Brand, log *slog.Logger,
) *UI

func (*UI) Registrar

func (u *UI) Registrar(mux *http.ServeMux)

Registrar wires the routes into the mux.

func (*UI) RegistrarLogin

func (u *UI) RegistrarLogin(mux *http.ServeMux, gate *auth.Gate)

RegistrarLogin wires the session routes. It is kept apart from Registrar because it only exists when there is a credential: without one, a login screen that always accepts would be worse than none.

Jump to

Keyboard shortcuts

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