como/crates/como_bin/src/main.rs

42 lines
963 B
Rust
Raw Normal View History

2022-10-04 12:06:00 +02:00
use std::sync::Arc;
2022-10-02 12:12:08 +02:00
2022-10-02 20:51:06 +02:00
mod error;
2022-10-04 11:07:14 +02:00
2022-10-04 11:06:48 +02:00
use clap::Parser;
2022-10-02 12:12:08 +02:00
2022-10-04 11:06:48 +02:00
use anyhow::Context;
2022-10-04 11:07:14 +02:00
2022-10-04 11:06:48 +02:00
use como_api::router::Api;
use como_infrastructure::{
configs::AppConfig, database::ConnectionPoolManager, register::ServiceRegister,
};
2022-10-04 11:07:14 +02:00
2022-10-02 12:12:08 +02:00
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing::info!("Loading dotenv");
dotenv::dotenv()?;
2022-10-04 11:06:48 +02:00
let config = Arc::new(AppConfig::parse());
2022-10-02 12:12:08 +02:00
tracing_subscriber::registry()
2022-10-04 12:06:00 +02:00
.with(tracing_subscriber::EnvFilter::new(&config.rust_log))
2022-10-02 12:12:08 +02:00
.with(tracing_subscriber::fmt::layer())
.init();
2022-10-04 11:06:48 +02:00
let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?;
2022-10-02 12:12:08 +02:00
let service_register = ServiceRegister::new(pool, config.clone()).await?;
2022-10-02 12:12:08 +02:00
2022-10-04 12:06:00 +02:00
Api::new(
config.api_port,
&config.cors_origin,
service_register.clone(),
)
.await
.context("could not initialize API")?;
2022-10-02 12:12:08 +02:00
Ok(())
}