30 lines
969 B
Rust
30 lines
969 B
Rust
use sqlx::postgres::PgPoolOptions;
|
|
use std::net::TcpListener;
|
|
use whitelist_api::{
|
|
configuration::get_configuration,
|
|
startup::run,
|
|
telemetry::{get_subscriber, init_subscriber},
|
|
};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let subscriber = get_subscriber("api".into(), "info".into(), std::io::stdout);
|
|
init_subscriber(subscriber);
|
|
|
|
let config = get_configuration().expect("Failed to read configuration!");
|
|
|
|
let db_pool = PgPoolOptions::new()
|
|
.max_connections(5)
|
|
.connect_with(config.database.with_db())
|
|
.await
|
|
.expect("Failed to connect to database!");
|
|
|
|
let address = format!("{}:{}", config.application.host, config.application.port);
|
|
let listener = TcpListener::bind(&address).expect(&format!("Failed to bind to {}!", &address));
|
|
|
|
tracing::info!("Starting application on {}", &address);
|
|
Ok(run(listener, db_pool)
|
|
.expect("Failed to run application!")
|
|
.await?)
|
|
}
|