como/crates/como_bin/src/main.rs
kjuulh 6e16fc6b2b
feat: move project to crates
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-10-21 11:14:58 +02:00

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(())
}