Documentation
¶
Overview ¶
Package config holds the typed application configuration.
There is no config("app.name") lookup: a wrong key is a compile error, not a runtime panic on the first request that happens to need it.
Index ¶
Constants ¶
const AppKeyLen = 32
AppKeyLen is the required length of the application key, in bytes.
const DefaultSQLitePath = "database/database.sqlite"
DefaultSQLitePath is where a fresh project keeps its database file. It mirrors Laravel's database/database.sqlite.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
AppName string
Env Env
HTTPAddr string
LogLevel slog.Level
// AppKey signs session cookies and CSRF tokens. Exactly AppKeyLen bytes.
AppKey []byte
// Database is the connection, described the way Laravel's .env describes it,
// because that is the file an Arandu project will be read next to.
Database DatabaseConfig
RedisURL string
SessionTTL time.Duration
CSRFTTL time.Duration
// TracingSecret enables the request Collector outside development for
// requests carrying it in the X-Arandu-Trace header. Empty disables it,
// which is the default: tracing must be opt-in, per deployment.
TracingSecret string
// Editor is the target of the "open in IDE" links on the error page.
// One of vscode, cursor, goland, zed.
Editor string
}
Config is a struct, not a map. Every field is validated at boot.
func Load ¶
Load reads the environment and validates it. It fails at boot, not on the first request.
type DatabaseConfig ¶ added in v0.2.0
type DatabaseConfig struct {
Connection data.Dialect
Database string // file path for SQLite, database name otherwise
Host string
Port string
Username string
Password string
// URL, when set, wins over every field above. Platforms hand out a single
// DATABASE_URL, and rebuilding it from parts is how a deployment ends up
// talking to the wrong database.
URL string
}
DatabaseConfig describes one connection.
The field names follow Laravel's DB_* variables on purpose: a developer coming from there should be able to read the .env of an Arandu project without a translation table. The default connection is SQLite, so a fresh checkout runs with nothing installed.
func (DatabaseConfig) DSN ¶ added in v0.2.0
func (d DatabaseConfig) DSN() string
DSN returns the connection string for the driver of this dialect.
func (DatabaseConfig) Redacted ¶ added in v0.2.0
func (d DatabaseConfig) Redacted() string
Redacted returns the connection as a string safe to log or show on the error page: the password is never part of it.
func (DatabaseConfig) SQLitePath ¶ added in v0.2.0
func (d DatabaseConfig) SQLitePath() string
SQLitePath returns the file the database lives in, or the empty string for a server-based connection. The application uses it to create the directory before opening: SQLite creates the file, never the directory above it.
func (DatabaseConfig) Validate ¶ added in v0.2.0
func (d DatabaseConfig) Validate() error
Validate reports a connection that cannot work, at boot rather than on the first query.