env

package
v0.1.136 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 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.

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

func AppSetting(name string) bool

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

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 Kind added in v0.1.112

func Kind(name string) string

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

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 Secret added in v0.1.112

func Secret(name string) bool

Secret says whether a setting's value is a secret by its name: shown as saved, never echoed.

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