Add config
This commit is contained in:
parent
21452c44b9
commit
af36ded031
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue