Module config

Module config 

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

  1. Create a base config file like config/base.toml1 to your project.
  2. Create an environment config file like config/develop.toml to your project.
  3. Set env to replace credentials. Use APP for prefix and separator __ for hierarchy. For example, APP_STOCK_DB__PASSWORD will replace config at field stock_db.password.
  4. In your code, create a config struct which mirror configuration from earlier steps.
  5. Call load_config with 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.


  1. 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.