42 lines
963 B
Rust
42 lines
963 B
Rust
use std::sync::Arc;
|
|
|
|
mod error;
|
|
|
|
use clap::Parser;
|
|
|
|
use anyhow::Context;
|
|
|
|
use como_api::router::Api;
|
|
use como_infrastructure::{
|
|
configs::AppConfig, database::ConnectionPoolManager, register::ServiceRegister,
|
|
};
|
|
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing::info!("Loading dotenv");
|
|
dotenv::dotenv()?;
|
|
|
|
let config = Arc::new(AppConfig::parse());
|
|
|
|
tracing_subscriber::registry()
|
|
.with(tracing_subscriber::EnvFilter::new(&config.rust_log))
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
|
|
let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?;
|
|
|
|
let service_register = ServiceRegister::new(pool, config.clone()).await?;
|
|
|
|
Api::new(
|
|
config.api_port,
|
|
&config.cors_origin,
|
|
service_register.clone(),
|
|
)
|
|
.await
|
|
.context("could not initialize API")?;
|
|
|
|
Ok(())
|
|
}
|