use dynamic_config::dynamic_config;
use serde::Deserialize;
#[dynamic_config(
name = "config",
paths = [
"dynamic-config/examples/deployment/etc",
"dynamic-config/examples/deployment/home",
],
key = "server",
profile_env = "APP_ENV",
)]
#[derive(Debug, Deserialize)]
struct ServerConfig {
host: String,
port: u16,
tls: bool,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ServerConfig::load()?;
println!(
"host = {} port = {} tls = {}",
config.host, config.port, config.tls
);
println!("\n{}", ServerConfig::check()?);
println!(
"\n`host` comes from etc/, `port` from home/. With APP_ENV=production, \
home/config.production.json layers over home/config.json."
);
println!(
"\nA profile variant sits directly on top of *its own* base, so a later \
directory's plain file still wins over an earlier directory's variant. \
The search order is the layering order; the profile is not a layer of \
its own above it."
);
Ok(())
}