Documentation
¶
Overview ¶
Package prea runs a Preá app: it loads the config of the active profile, opens the database, applies the migrations and serves the modules. The app's main only passes what it declares:
prea.Run(prea.Config{Modules: preas.Modules, Middlewares: preas.Middlewares, Security: preas.Security})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(cfg Config)
Run starts the app and serves until SIGINT or SIGTERM; a startup error is logged and exits the process with code 1. With PREA_MIGRATE set (by prea migrate) it runs that migrations command instead of serving.
func Test ¶
Test builds the app like Run, with the tests profile (config/application-tests.yaml), and returns its handler for httptest:
app := prea.Test(t, prea.Config{Modules: []*core.Module{Module}})
app.ServeHTTP(w, httptest.NewRequest("GET", "/health", nil))
It runs from the project root, the nearest directory with a go.mod above the test's, so config/ and migrations/ are found from any package. The app and the database close when the test ends.
Types ¶
type Config ¶
type Config struct {
Modules []*core.Module
Middlewares []any
Security core.Security // Security.TrustedProxies, when nil, comes from server.trusted_proxies
Logging Logging
}
Config is what the app declares in code. The rest comes from config/application.yaml and the active profile:
- server.port and server.mode, required;
- server.read_header_timeout, read_timeout, write_timeout, idle_timeout, shutdown_timeout, max_header_bytes and trusted_proxies, with defaults;
- database.url (without it the app has no database), database.schema and database.migrations;
- security.jwt.secret, applied only when set.