2020-11-01 21:25:11 +00:00
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
|
use std::net::TcpListener;
|
2020-12-05 17:19:11 +00:00
|
|
|
use zero2prod::configuration::get_configuration;
|
|
|
|
use zero2prod::startup::run;
|
|
|
|
use zero2prod::telemetry::{get_subscriber, init_subscriber};
|
2020-11-01 21:25:11 +00:00
|
|
|
|
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
let subscriber = get_subscriber("zero2prod".into(), "info".into());
|
|
|
|
init_subscriber(subscriber);
|
|
|
|
|
|
|
|
let configuration = get_configuration().expect("Failed to read configuration.");
|
|
|
|
let connection_pool = PgPoolOptions::new()
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(2))
|
|
|
|
.connect_with(configuration.database.with_db())
|
|
|
|
.await
|
|
|
|
.expect("Failed to connect to Postgres.");
|
|
|
|
|
|
|
|
let address = format!(
|
|
|
|
"{}:{}",
|
|
|
|
configuration.application.host, configuration.application.port
|
|
|
|
);
|
|
|
|
let listener = TcpListener::bind(address)?;
|
|
|
|
run(listener, connection_pool)?.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|