1
0
Fork 0

Add config

This commit is contained in:
Alex Kotov 2023-01-25 21:13:04 +04:00
parent 21452c44b9
commit af36ded031
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 30 additions and 1 deletions

23
src/config.rs Normal file
View File

@ -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)
}
}

View File

@ -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
}