Module sozu_command_lib::config

source ·
Expand description

parse TOML config and generate requests from it

§Sōzu’s configuration

This module is responsible for parsing the config.toml provided by the flag --config when starting Sōzu.

Here is the workflow for generating a working config:

    config.toml   ->   FileConfig    ->  ConfigBuilder   ->  Config

config.toml is parsed to FileConfig, a structure that itself contains a lot of substructures whose names start with File- and end with -Config, like FileHttpFrontendConfig for instance.

The instance of FileConfig is then passed to a ConfigBuilder that populates a final Config with listeners and clusters.

To illustrate:

use sozu_command_lib::config::{FileConfig, ConfigBuilder};

let file_config = FileConfig::load_from_path("../config.toml")
    .expect("Could not load config.toml");

let config = ConfigBuilder::new(file_config, "../assets/config.toml")
    .into_config()
    .expect("Could not build config");

Note that the path to config.toml is used twice: the first time, to parse the file, the second time, to keep the path in the config for later use.

However, there is a simpler way that combines all this:

use sozu_command_lib::config::Config;

let config = Config::load_from_path("../assets/config.toml")
    .expect("Could not build config from the path");

§How values are chosen

Values are chosen in this order of priority:

  1. values defined in a section of the TOML file, for instance, timeouts for a specific listener
  2. values defined globally in the TOML file, like timeouts or buffer size
  3. if a variable has not been set in the TOML file, it will be set to a default defined here

Structs§

Enums§

Constants§

Functions§