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 ¶
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.
Variables ¶
This section is empty.
Functions ¶
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 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.
Types ¶
This section is empty.