Documentation
¶
Overview ¶
Package env fills a configuration struct from the environment, so secrets and per-deployment settings never live in lidza.json or code.
type Config struct {
DatabaseURL string `env:"DATABASE_URL" required:"true"`
Workers int `env:"WORKERS" default:"4"`
Timeout time.Duration `env:"TIMEOUT" default:"30s"`
Debug bool `env:"DEBUG"`
Origins []string `env:"CORS_ORIGINS"`
}
Load reads, in order of increasing precedence: the settings files (Files: .env, .env.local, .env.<mode>, .env.<mode>.local), the app's credentials (config/credentials.yml.enc, decrypted with the master key, plus the values saved at runtime), the process environment. Mode is LIDZA_MODE ("dev" under lidza dev, "test" under lidza test), else "production". Under test the sealed credentials file is not read: tests never get the deployment's keys.
Index ¶
- Constants
- func AppSetting(name string) bool
- func Files() []string
- func Fill(dst any, values map[string]string) error
- func Kind(name string) string
- func Load(dir string, dst any) error
- func Mode() string
- func Origins(dir string) (map[string]string, error)
- func Secret(name string) bool
- func Values(dir string) (map[string]string, error)
Constants ¶
const ( OriginDotEnv = ".env" OriginCredentials = "credentials" // config/credentials.yml.enc OriginSaved = "saved" // a value saved at runtime (the admin pages) OriginProcess = "environment" // the process environment )
Origin layers, lowest precedence first, as Origins reports them.
const ( KindInfra = "infra" KindApp = "app" )
The two kinds of setting. An app's configuration (its API keys, the providers and models it uses, its address, sender, buckets, admins, signing secret) lives in the app: saved in its database (the admin pages, lidza settings set) and seeded for development by the sealed credentials file. The environment is for the deployment: where the database is, the master key, addresses and ports, logging and tracing, and performance tuning (pool sizes, workers, timeouts, rate limits, retention). An app moved to another server then takes its configuration along in its database, and the new environment says only how to run it.
Variables ¶
This section is empty.
Functions ¶
func AppSetting ¶ added in v0.1.112
AppSetting reports whether name is one of the framework's app settings (KindApp and named like the packs' settings), so unrelated variables (PATH, HOME) are never taken for one.
func Files ¶
func Files() []string
Files are the settings files, lowest precedence first: .env, then .env.local, then .env.<mode> (.env.test is committed), then .env.<mode>.local. The .local ones are this checkout's own and never committed: a git worktree's databases (lidza install writes them), a developer's one-off value.
func Fill ¶
Fill sets dst's fields from values, using the `env`, `default` and `required` tags. Exported.
func Kind ¶ added in v0.1.112
Kind says whether a setting belongs to the deployment's environment (KindInfra) or in the app (KindApp). Every name not recognised as the deployment's is the app's.
func Load ¶
Load fills dst (a pointer to a struct) from .env files in dir and the process environment. Missing required variables and unparsable values are reported together in one error.
func Origins ¶
Origins reports, for every name Values returns, the layer its value comes from: OriginDotEnv (one of Files, reported as the file's name), OriginCredentials, OriginSaved or OriginProcess. A value from the process environment wins over everything the app can save.
Types ¶
This section is empty.