Expand description
A simple config module wrapping over [config::Config] module.
At Avantis, we support environment config file system for most configurations
include settings (ex. DEBUG=true) and data access (ie. database or API endpoints).
We also support overriding mechanism via environment variables for credentials
(ie. usernames, passwords, API keys). This keep credentials safe from accidentially
upload to code repository and provide a single access point to credentials for easier
rotation.
For most projects, we recommend using load_config which take an Environment enum value, and return a config model struct.
- Create a base config file like
config/base.toml1 to your project. - Create an environment config file like
config/develop.tomlto your project. - Set env to replace credentials. Use
APPfor prefix and separator__for hierarchy. For example,APP_STOCK_DB__PASSWORDwill replace config at fieldstock_db.password. - In your code, create a config struct which mirror configuration from earlier steps.
- Call
load_configwith selected Environment into the struct from step 4.
For example usage, see here and its config files here.
If you need to customize load mechanism, see load_custom_config or maybe use [config::Config] directly instead.
Any format listed in [config::FileFormat] can be used. ↩
Enums§
- Environment
- Application environment. Affect configuration file loaded by load_config.
Functions§
- load_
config - Load config from selected Environment. Returns a Result containing config struct. Convenience load_custom_config.
- load_
config_ by_ path - Load config by path from selected Environment and [Path]. Returns a Result containing config struct. Convenience load_custom_config.
- load_
custom_ config - Load config from custom sources. Returns a Result containing config struct.