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 ¶
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
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 ¶
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 ¶
HTTPServer returns the configured server. The timeouts exist because net/http's default is none: without them, a slow connection holds a handler indefinitely.
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