config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 12 Imported by: 0

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.

Load is the one entry point. It reads a .env from the working directory when there is one -- filling only what the environment has not already defined -- and then validates the result. There is no second loader and no flag that moves the file.

Index

Constants

View Source
const AppKeyLen = 32

AppKeyLen is the required length of the application key, in bytes.

View Source
const DefaultSQLitePath = "database/database.sqlite"

DefaultSQLitePath is where a fresh project keeps its database file.

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, named the way a .env conventionally names it,
	// so nobody needs a translation table to read one.
	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

func Load() (Config, error)

Load reads the environment and validates it. It fails at boot, not on the first request.

A .env in the working directory is read first, and it only fills variables the environment does not already define -- see loadEnvFile. It is read here rather than by the application, because a step the application has to remember is a step that gets forgotten: this one was, and `aru migrate` failed on every new project for it.

func (Config) IsDev

func (c Config) IsDev() bool

IsDev reports whether the debug surface is allowed to exist.

func (Config) Validate

func (c Config) Validate() error

Validate reports the first configuration error, with the command that fixes it whenever one exists.

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 are the conventional DB_* ones on purpose: an .env should be readable at a glance, by anyone who has read one before. 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.

type Env

type Env string

Env is the deployment environment. It gates everything that must never run outside development, starting with the debug error page.

const (
	EnvDev     Env = "dev"
	EnvStaging Env = "staging"
	EnvProd    Env = "prod"
)

Supported environments.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL