Documentation
¶
Overview ¶
Package httpapi is the HTTP transport layer: routing, middleware, JSON encoding and the mapping from domain errors to status codes. It contains NO business rules; handlers decode a request, call a service, and encode the result.
Request flow (outermost middleware first):
requestID -> accessLog -> metrics -> recoverer -> cors -> rateLimit -> ServeMux
|
(per route) [csrf, strict rate limit] requireAuth -> handler -> service -> store
requireAuth accepts a Bearer JWT or a session cookie; see its documentation.
Order matters:
- requestID is outermost so every later log line carries the id.
- accessLog and metrics sit outside recoverer so they see the 500 that a panic becomes.
- rateLimit runs before routing and auth, so floods are rejected cheaply, before any token parsing or database work.
- Nothing between metrics and the mux may replace the *http.Request (see routeOf).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Deps ¶
type Deps struct {
Logger *slog.Logger
Auth *service.AuthService
Projects *service.ProjectService
Tasks *service.TaskService
Tokens TokenVerifier
DB Pinger
// SessionAuth (required) powers the cookie-session mode and the /v1/session-auth/* endpoints.
SessionAuth *service.SessionAuthService
// GitHub enables "Sign in with GitHub" when non-nil; the OAuth routes are 404 otherwise.
GitHub *auth.GitHub
// CookieSecure sets the Secure attribute on cookies. true in production; false only for
// plain-http local development.
CookieSecure bool
// Draining flips to true when shutdown begins; /readyz then returns 503 so the load balancer
// stops sending new traffic while in-flight requests finish. May be nil.
Draining *atomic.Bool
RateRPS float64
RateBurst int
CORSOrigins []string
// AuthRateRPS/AuthRateBurst are the (much stricter) per-IP limit for credential endpoints:
// sign-in, sign-up, password reset, verification mail. Zero falls back to RateRPS/RateBurst.
AuthRateRPS float64
AuthRateBurst int
// CleanupInterval is how often expired sessions and tokens are deleted (default 1 hour).
CleanupInterval time.Duration
}
Deps is everything the HTTP layer needs, passed explicitly (no globals, no init()).
type SessionVerifier ¶
type SessionVerifier interface {
Authenticate(ctx context.Context, token string) (service.SessionState, error)
}
SessionVerifier resolves a session cookie value. *service.SessionAuthService satisfies it.