Documentation
¶
Overview ¶
Package config loads typed application configuration from environment variables and .env files.
Values are resolved with this precedence, highest first: the process environment, .env.<APP_ENV>.local, .env.local (skipped when APP_ENV=test), .env.<APP_ENV>, .env. Structs are filled with Fill using `env` and `default` struct tags.
Index ¶
Constants ¶
const MinKeyLen = 32
MinKeyLen is the minimum APP_KEY length in bytes.
Variables ¶
This section is empty.
Functions ¶
func Fill ¶
Fill sets the exported fields of the struct pointed to by dst from src.
A field is read from the key in its `env` tag, falling back to its `default` tag. Struct fields without an `env` tag are filled recursively. Supported kinds: string, bool, ints, uints, floats, time.Duration, []string (comma-separated), *url.URL, Secret and any encoding.TextUnmarshaler. All conversion errors are returned together.
func GenerateKey ¶
func GenerateKey() string
GenerateKey returns a new random APP_KEY value ("base64:..." of 32 bytes).
Types ¶
type Entry ¶
type Entry struct {
Key string
Value string
// Expand reports whether ${VAR} references in Value must be expanded.
// Single-quoted values are literal.
Expand bool
}
Entry is one KEY=VALUE pair parsed from a .env file.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is the decoded application key (APP_KEY). Never use it directly for cryptography: derive a purpose-specific key with Derive.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret holds a sensitive value. Every formatting path (fmt, encoding/json, log/slog) prints "[redacted]"; use Reveal to read the value.
func (Secret) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Secret) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is a resolved set of configuration values.
func LoadSource ¶
func LoadSource( fsys fs.FS, getenv func(string) (string, bool), readFile func(string) ([]byte, error), ) (*Source, error)
LoadSource reads .env files from fsys and merges them with the process environment provided by getenv (use os.LookupEnv in production code). readFile resolves "@file:" values; nil disables them.