./config directory. A new project ships with base.toml, dev.toml, and prod.toml. Shared values go in base.toml, while each environment’s file overrides what it needs.
Extending Files
Config files declare what they build on with theextends key:
config/dev.toml
dev.toml loads everything from base.toml plus the values above. The extending file itself wins when keys collide with an extended file; between files in the extends list, earlier ones win.
Choosing a Config File
The-config flag selects which file to load. It defaults to ./config/dev.toml:
-set with TOML syntax. Separate multiple overrides with ;:
Reading Config in Your Package
Each package loads its own section withcconfig.Loader. By convention this lives in config.go:
pkg/rockets/config.go
LoadConfig to the package’s WireModule and take Config as a field on any params struct that needs it.
If the section is missing from the config file, Load is a no-op and your struct keeps its zero values. For keys omitted from a section that is present, you may set defaults with the default tag. If you would like to cover a missing section as well, apply defaults after loading:
Environment Variables
Config files are rendered as Go templates before parsing, with all environment variables available under.EnvVars:
config/prod.toml
Secrets
There are two patterns for keeping secrets out of your repository. For development, put secrets in a gitignored file and pull it in viaextends:
config/dev.toml
local_example.toml with the shape of the file and blank values, so that new teammates know what to fill in.
For production, use the exec template function to fetch secrets from a secret manager at startup. The command runs through sh -c and its trimmed stdout is substituted in:
config/prod.toml