mirror of
https://github.com/kristoferssolo/zero2prod.git
synced 2025-10-21 20:10:40 +00:00
25 lines
847 B
Rust
25 lines
847 B
Rust
use secrecy::ExposeSecret;
|
|
use sqlx::postgres::PgPoolOptions;
|
|
use tokio::net::TcpListener;
|
|
use zero2prod::{
|
|
config::get_config,
|
|
routes::route,
|
|
telemetry::{get_subscriber, init_subscriber},
|
|
};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
let subscriber = get_subscriber("zero2prod", "info", std::io::stdout);
|
|
init_subscriber(subscriber);
|
|
let config = get_config().expect("Failed to read configuation.");
|
|
let pool = PgPoolOptions::new()
|
|
.connect_lazy(config.database.to_string().expose_secret())
|
|
.expect("Failed to create Postgres connection pool.");
|
|
let addr = format!("{}:{}", config.application.host, config.application.port);
|
|
let listener = TcpListener::bind(addr)
|
|
.await
|
|
.expect("Failed to bind port 8000.");
|
|
|
|
axum::serve(listener, route(pool)).await
|
|
}
|