env

package
v0.1.99 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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

func Fill(dst any, values map[string]string) error

Fill sets dst's fields from values, using the `env`, `default` and `required` tags. Exported.

func Load

func Load(dir string, dst any) error

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 Mode

func Mode() string

Mode returns the run mode: the value of LIDZA_MODE, or "production".

func Origins

func Origins(dir string) (map[string]string, error)

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.

func Values

func Values(dir string) (map[string]string, error)

Values returns everything Load would read, as a map: the .env files, the credentials, the process environment.

Types

This section is empty.

Jump to

Keyboard shortcuts

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