mailApp/src/main.rs
2022-01-03 17:11:11 +10:00

26 lines
974 B
Rust

use std::net::TcpListener;
use sqlx::postgres::PgPoolOptions;
use mail_app::startup::run;
use mail_app::configuration::get_configuration;
use mail_app::telemetry::{get_subscriber, init_subscriber};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let subscriber = get_subscriber("mail_app".into(), "info".into(), std::io::stdout);
init_subscriber(subscriber);
// Attempt to read from config
let configuration = get_configuration().expect("Failed to read configuration data.");
// Configure connection to database for our startup
let connection_pool = PgPoolOptions::new()
.connect_timeout(std::time::Duration::from_secs(2))
.connect_lazy_with(configuration.database.with_db());
// Take port from settings file
let address = format!("{}:{}", configuration.application.host, configuration.application.port);
let listener = TcpListener::bind(address)?;
run(listener, connection_pool)?.await?;
Ok(())
}