2023-11-19 17:54:27 +00:00
|
|
|
use config::Config;
|
|
|
|
use serde_derive::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
#[serde(default)]
|
|
|
|
#[allow(unused)]
|
|
|
|
pub struct Logging {
|
|
|
|
pub level: String,
|
|
|
|
pub file: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
#[serde(default)]
|
|
|
|
#[allow(unused)]
|
|
|
|
pub struct Settings {
|
|
|
|
pub database: String,
|
|
|
|
pub port: u16,
|
|
|
|
pub host: String,
|
|
|
|
pub logging: Logging,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Settings {
|
|
|
|
database: String::from("sqlite://emgauwa-core.sqlite"),
|
|
|
|
port: 5000,
|
|
|
|
host: String::from("127.0.0.1"),
|
|
|
|
logging: Logging::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Logging {
|
|
|
|
fn default() -> Self {
|
|
|
|
Logging {
|
|
|
|
level: String::from("info"),
|
|
|
|
file: String::from("stdout"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-22 19:06:20 +00:00
|
|
|
pub fn init() -> Settings {
|
|
|
|
Config::builder()
|
2023-11-19 17:54:27 +00:00
|
|
|
.add_source(config::File::with_name("emgauwa-core"))
|
|
|
|
.add_source(
|
|
|
|
config::Environment::with_prefix("EMGAUWA")
|
|
|
|
.prefix_separator("_")
|
|
|
|
.separator("__"),
|
|
|
|
)
|
|
|
|
.build()
|
|
|
|
.unwrap()
|
|
|
|
.try_deserialize::<Settings>()
|
2023-11-22 19:06:20 +00:00
|
|
|
.unwrap_or_else(|_| panic!("Error reading settings."))
|
2023-11-19 17:54:27 +00:00
|
|
|
}
|