2024-03-29 16:20:53 -04:00
|
|
|
use std::net::TcpListener;
|
|
|
|
|
2024-05-07 16:10:09 -04:00
|
|
|
use email_newsletter_api::telemetry::{get_subscriber, init_subscriber};
|
2024-05-03 16:14:36 -04:00
|
|
|
use email_newsletter_api::{configuration::get_configuration, startup};
|
2024-05-08 17:53:41 -04:00
|
|
|
use secrecy::ExposeSecret;
|
2024-05-04 15:27:47 -04:00
|
|
|
use sqlx::PgPool;
|
2024-03-28 11:42:08 -04:00
|
|
|
|
|
|
|
#[tokio::main]
|
2024-05-03 15:43:34 -04:00
|
|
|
async fn main() -> Result<(), std::io::Error> {
|
2024-05-03 16:14:36 -04:00
|
|
|
let configuration = get_configuration().expect("Failed to read configuration");
|
|
|
|
|
2024-05-07 21:36:16 -04:00
|
|
|
let subscriber = get_subscriber(
|
|
|
|
"email_newsletter_api".into(),
|
|
|
|
"info".into(),
|
|
|
|
std::io::stdout,
|
|
|
|
);
|
2024-05-07 16:10:09 -04:00
|
|
|
init_subscriber(subscriber);
|
2024-05-06 00:49:17 -04:00
|
|
|
|
2024-05-10 19:38:07 -04:00
|
|
|
let db_conn = PgPool::connect_lazy(configuration.database.connection_string().expose_secret())
|
2024-05-04 15:27:47 -04:00
|
|
|
.expect("Failed to connect to PostgreSQL");
|
|
|
|
|
2024-05-10 19:38:07 -04:00
|
|
|
let listener = TcpListener::bind(format!(
|
|
|
|
"{}:{}",
|
|
|
|
configuration.application.host, configuration.application.port
|
|
|
|
))
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
panic!(
|
|
|
|
"Can't bind to port {} at localhost",
|
|
|
|
configuration.application.port
|
|
|
|
)
|
|
|
|
});
|
2024-03-29 16:20:53 -04:00
|
|
|
|
2024-03-29 15:36:54 -04:00
|
|
|
// Move the error up the call stack
|
|
|
|
// otherwise await for the HttpServer
|
2024-05-04 15:27:47 -04:00
|
|
|
startup::run(listener, db_conn)?.await
|
2024-03-23 19:04:25 -04:00
|
|
|
}
|