From af36ded031863e4c38c25c202d63c0eddc1ad557 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 25 Jan 2023 21:13:04 +0400 Subject: [PATCH] Add config --- src/config.rs | 23 +++++++++++++++++++++++ src/main.rs | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/config.rs diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9b60921 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,23 @@ +const DEFAULT_ADDRESS: &str = "127.0.0.1"; +const DEFAULT_PORT: u16 = 3000; + +#[derive(Debug, Clone)] +pub struct Config { + address: String, + port: u16, +} + +impl Default for Config { + fn default() -> Self { + Self { + address: DEFAULT_ADDRESS.to_string(), + port: DEFAULT_PORT, + } + } +} + +impl Config { + pub fn bind(&self) -> String { + format!("{}:{}", self.address, self.port) + } +} diff --git a/src/main.rs b/src/main.rs index 566f2ca..3ba214d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,18 @@ +mod config; + +use config::Config; + #[actix_web::main] async fn main() -> std::io::Result<()> { + let config = Config::default(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); actix_web::HttpServer::new(|| { actix_web::App::new() .wrap(actix_web::middleware::Logger::default()) }) - .bind("127.0.0.1:3000")? + .bind(config.bind())? .run() .await }