2023-11-23 15:00:24 +00:00
|
|
|
pub fn load_settings<T>(config_name: &str, env_prefix: &str) -> T
|
|
|
|
where
|
2023-11-27 11:49:40 +00:00
|
|
|
for<'de> T: serde::Deserialize<'de>,
|
2023-11-23 15:00:24 +00:00
|
|
|
{
|
2023-11-27 11:49:40 +00:00
|
|
|
let default_file = config::File::with_name(&format!("emgauwa-{}", config_name)).required(false);
|
2023-11-23 15:00:24 +00:00
|
|
|
|
|
|
|
config::Config::builder()
|
|
|
|
.add_source(default_file)
|
|
|
|
.add_source(
|
|
|
|
config::Environment::with_prefix(&format!("EMGAUWA_{}", env_prefix))
|
|
|
|
.prefix_separator("__")
|
|
|
|
.separator("__"),
|
|
|
|
)
|
|
|
|
.build()
|
|
|
|
.expect("Error building settings")
|
|
|
|
.try_deserialize::<T>()
|
|
|
|
.expect("Error reading settings")
|
2023-11-27 11:49:40 +00:00
|
|
|
}
|