api

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package api expoe a interface HTTP do Brevis.

Usa net/http puro. O roteamento por metodo e path do ServeMux (Go 1.22+) cobre o que precisamos, e a regra 6 do plano pede evitar framework quando a stdlib resolve. O trabalho dificil deste sistema esta na fila, no scheduler e na maquina de estados — nao no HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acoes

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

Acoes 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 Checker

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

Checker e uma dependencia que o readiness consulta. Interface pequena de proposito (regra 5): o postgres.Pool ja a satisfaz sem adaptador.

type Definicoes

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

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

type Execucoes

type Execucoes interface {
	Buscar(ctx context.Context, id uuid.UUID) (run.Run, error)
	EstadoDosNos(ctx context.Context, id uuid.UUID) (map[string]postgres.EstadoNo, error)
	LogsDaRun(ctx context.Context, id uuid.UUID) ([]postgres.LogDoPasso, error)
}

Execucoes reads a Run and the state of its steps.

type Leitura

type Leitura interface {
	Indicadores(ctx context.Context, janela time.Duration) (postgres.Indicadores, error)
	ExecucoesPorHora(ctx context.Context, horas int) ([]postgres.Balde, error)
	EmAndamento(ctx context.Context, limite int) ([]postgres.ResumoRun, error)
	UltimasRuns(ctx context.Context, limite int) ([]postgres.ResumoRun, error)
	Runs(ctx context.Context, f postgres.FiltroRuns) ([]postgres.ResumoRun, error)
	ContarRuns(ctx context.Context, f postgres.FiltroRuns) (int, error)
	RunsDoWorkflow(ctx context.Context, slug string, limite int) ([]postgres.ResumoRun, error)
	Workflows(ctx context.Context) ([]postgres.ResumoWorkflow, error)
	Agendas(ctx context.Context) ([]postgres.AgendaResumo, error)
	Projetos(ctx context.Context) ([]postgres.ResumoProjeto, error)
	ProfundidadeDaFila(ctx context.Context) (int, int, error)
}

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

type Server

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

Server carrega o roteador e as dependencias que o readiness consulta.

func NewServer

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

NewServer monta o roteador. Os checkers sao nomeados para que o /ready diga QUAL dependencia falhou, e nao apenas que algo falhou.

`ui` pode ser nil: um processo que so serve health check nao precisa das paginas, e exigi-las acoplaria o servidor ao banco sem necessidade.

func NewServerAutenticado

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

NewServerAutenticado e o mesmo, exigindo sessao quando a credencial esta configurada. `inseguro` manda o cookie sem a flag Secure — necessario apenas para http puro em desenvolvimento, porque um cookie Secure nunca chega de volta por http e o login pareceria simplesmente nao funcionar.

func (*Server) HTTPServer

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

HTTPServer devolve o servidor configurado. Os timeouts existem porque o default do net/http e nenhum: sem eles, uma conexao lenta segura um handler indefinidamente.

func (*Server) ServeHTTP

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

ServeHTTP faz do Server um http.Handler, com log de acesso.

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 Definicoes, e Execucoes, a Acoes, m branding.Marca, 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, portao *auth.Portao)

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