30 lines
958 B
Rust
30 lines
958 B
Rust
use anyhow::Context;
|
|
use tempus::{config::Config, db, routes};
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "tempus=info,tower_http=info".into()),
|
|
)
|
|
.init();
|
|
|
|
let config = Config::from_env()?;
|
|
let pool = db::connect(&config.database_url)
|
|
.await
|
|
.with_context(|| format!("cannot open {}", config.database_url))?;
|
|
|
|
let listener = tokio::net::TcpListener::bind(config.addr)
|
|
.await
|
|
.with_context(|| format!("cannot listen on {}", config.addr))?;
|
|
tracing::info!(db = %config.database_url, "Tempus disponible sur http://{}", config.addr);
|
|
axum::serve(listener, routes::app(pool))
|
|
.with_graceful_shutdown(async {
|
|
let _ = tokio::signal::ctrl_c().await;
|
|
})
|
|
.await?;
|
|
Ok(())
|
|
}
|