diff --git a/emgauwa-controller/src/settings.rs b/emgauwa-controller/src/settings.rs index a2b6ead..c05d8b6 100644 --- a/emgauwa-controller/src/settings.rs +++ b/emgauwa-controller/src/settings.rs @@ -1,6 +1,15 @@ use config::Config; +use emgauwa_lib::constants; use serde_derive::Deserialize; +#[derive(Clone, Debug, Deserialize)] +#[serde(default)] +#[allow(unused)] +pub struct Core { + pub host: String, + pub port: u16, +} + #[derive(Clone, Debug, Deserialize)] #[serde(default)] #[allow(unused)] @@ -14,8 +23,6 @@ pub struct Logging { #[allow(unused)] pub struct Settings { pub database: String, - pub port: u16, - pub host: String, pub logging: Logging, } @@ -23,13 +30,20 @@ impl Default for Settings { fn default() -> Self { Settings { database: String::from("sqlite://emgauwa-controller.sqlite"), - port: 5000, - host: String::from("127.0.0.1"), logging: Logging::default(), } } } +impl Default for Core { + fn default() -> Self { + Core { + host: String::from("127.0.0.1"), + port: constants::DEFAULT_PORT, + } + } +} + impl Default for Logging { fn default() -> Self { Logging { diff --git a/emgauwa-core.toml b/emgauwa-core.toml index 2d0d9b2..b103fba 100644 --- a/emgauwa-core.toml +++ b/emgauwa-core.toml @@ -1,4 +1,4 @@ -port = 5000 +port = 4419 host = "127.0.0.1" database = "sqlite://emgauwa-core.sqlite" diff --git a/emgauwa-core/src/main.rs b/emgauwa-core/src/main.rs index 352dcd6..f0a6864 100644 --- a/emgauwa-core/src/main.rs +++ b/emgauwa-core/src/main.rs @@ -23,6 +23,7 @@ async fn main() -> std::io::Result<()> { let pool = emgauwa_lib::db::init(&settings.database).await; + log::info!("Starting server on {}:{}", settings.host, settings.port); HttpServer::new(move || { App::new() .wrap( diff --git a/emgauwa-core/src/settings.rs b/emgauwa-core/src/settings.rs index 44b29db..ea0ccb0 100644 --- a/emgauwa-core/src/settings.rs +++ b/emgauwa-core/src/settings.rs @@ -1,4 +1,5 @@ use config::Config; +use emgauwa_lib::constants; use serde_derive::Deserialize; #[derive(Clone, Debug, Deserialize)] @@ -23,7 +24,7 @@ impl Default for Settings { fn default() -> Self { Settings { database: String::from("sqlite://emgauwa-core.sqlite"), - port: 5000, + port: constants::DEFAULT_PORT, host: String::from("127.0.0.1"), logging: Logging::default(), } @@ -44,11 +45,11 @@ pub fn init() -> Settings { .add_source(config::File::with_name("emgauwa-core")) .add_source( config::Environment::with_prefix("EMGAUWA_CORE") - .prefix_separator("_") + .prefix_separator("__") .separator("__"), ) .build() .unwrap() .try_deserialize::() - .unwrap_or_else(|_| panic!("Error reading settings.")) + .expect("Error reading settings.") } diff --git a/emgauwa-lib/src/constants.rs b/emgauwa-lib/src/constants.rs new file mode 100644 index 0000000..649705b --- /dev/null +++ b/emgauwa-lib/src/constants.rs @@ -0,0 +1 @@ +pub const DEFAULT_PORT: u16 = 4419; diff --git a/emgauwa-lib/src/lib.rs b/emgauwa-lib/src/lib.rs index fc678b3..0de9d46 100644 --- a/emgauwa-lib/src/lib.rs +++ b/emgauwa-lib/src/lib.rs @@ -1,3 +1,4 @@ +pub mod constants; pub mod db; pub mod handlers; pub mod return_models;