use dynamic_config::dynamic_config;
use serde::Deserialize;
#[dynamic_config(files = ["dynamic-config/examples/secrets.json"], key = "db", env = "APP_")]
#[derive(Deserialize)]
struct DatabaseConfig {
host: String,
username: String,
#[config(secret)]
password: String,
#[allow(dead_code)]
#[config(secret)]
api_token: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = DatabaseConfig::load()?;
println!("connecting as {} to {}", config.username, config.host);
println!("password length: {}", config.password.len());
println!("\n{config:?}");
println!("\nWhat this covers:");
println!(" • `{{:?}}` anywhere — a log line, a panic message, a tracing field");
println!(" • a reload diff, which reports paths and never values");
println!(" • `check()`, which reports origins and never values");
println!("\nWhat it does not:");
println!(" • `println!(\"{{}}\", config.password)` — an explicit read is yours to make");
println!(" • `save()`, which writes what it was asked to write (0600 on Unix)");
println!(" • the config file itself, which holds the value in the clear");
Ok(())
}