Documentation
¶
Overview ¶
Package configdotenv reads dotenv (.env) configuration through the config codec seam.
It is a sibling of the config core, not part of it, and adds no dependency at all — a dotenv file is simple enough to read with the standard library.
config.NewStore(ctx, config.WithFiles(fsys, "/etc/app.yaml"), // YAML, the default config.WithBackend(configdotenv.New(fsys, "/etc/app.env")), )
Keys nest on underscores ¶
A dotenv key is lower-cased and its underscores become dotted-key separators, so `DATABASE_HOST=localhost` reads as `database.host`, and a dotenv layer merges into a nested YAML or JSON one by the same paths. This matches how the environment backend maps an unmatched variable, and it is deterministic — a key with a literal underscore in its name cannot be expressed, by design.
No interpolation ¶
A `${VAR}` in a value is left as written, never expanded. Expanding it would read the process environment through a side door the Store does not own — exactly the unprefixed-environment leak the environment backend's required prefix exists to prevent. A consumer who wants environment values adds config.WithEnv as an ordinary layer, where the prefix applies and provenance names the variable.
Read-only ¶
Values are strings; the read path casts. The format is read-only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Codec ¶ added in v0.2.0
type Codec struct{}
Codec decodes KEY=value lines into layer values. New uses it, and it is exported so a backend adapter can reuse it as a value decoder — a key whose value is a dotenv document, decoded via that adapter's WithValueCodec option. It is a config.Codec.