mod mutate; use std::{ net::{Ipv6Addr, SocketAddr}, ops::Deref, sync::Arc }; use sqlx::PgPool; use warden_stack::{cache::RedisManager, tracing::SdkTracerProvider, Configuration}; use crate::AppConfig; #[derive(Clone)] pub struct AppHandle(pub Arc); impl Deref for AppHandle { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } #[derive(Clone)] pub struct Services { pub postgres: PgPool, pub cache: RedisManager, } #[derive(Clone)] pub struct AppState { pub addr: SocketAddr, pub services: Services, pub config: Configuration, pub app_config: AppConfig, pub tracer_provider: Option, } impl AppState { pub fn new( services: Services, config: Configuration, tracer_provider: Option, ) -> anyhow::Result { let listen_address = SocketAddr::from((Ipv6Addr::UNSPECIFIED, config.application.port)); let app_config: AppConfig = serde_json::from_value(config.misc.clone())?; Ok(Self { addr: listen_address, services, config, tracer_provider, app_config, }) } }