aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/state.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-12 05:13:32 +0200
committerrtkay123 <dev@kanjala.com>2025-08-12 05:13:32 +0200
commitc5ea875f544824b0c042bf7c0a58b3134f9c0373 (patch)
tree4913d4ff2b408c7157e33894e40deec570ecce9e /crates/configuration/src/state.rs
parent9c850d6c4d0ed468709c2eb5340d7b64bbb9aa68 (diff)
downloadwarden-c5ea875f544824b0c042bf7c0a58b3134f9c0373.tar.bz2
warden-c5ea875f544824b0c042bf7c0a58b3134f9c0373.zip
feat(config): get active routing
Diffstat (limited to 'crates/configuration/src/state.rs')
-rw-r--r--crates/configuration/src/state.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/configuration/src/state.rs b/crates/configuration/src/state.rs
new file mode 100644
index 0000000..7672891
--- /dev/null
+++ b/crates/configuration/src/state.rs
@@ -0,0 +1,51 @@
+mod cache_key;
+mod routing;
+
+use async_nats::jetstream::Context;
+use sqlx::PgPool;
+use std::{ops::Deref, sync::Arc};
+use tonic::transport::Endpoint;
+use tracing::error;
+use warden_stack::{Configuration, cache::RedisManager};
+
+use crate::{
+ cnfg::LocalConfig,
+ server::grpc::interceptor::{Intercepted, MyInterceptor},
+};
+
+#[derive(Clone)]
+pub struct AppHandle(Arc<AppState>);
+
+impl Deref for AppHandle {
+ type Target = Arc<AppState>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+#[derive(Clone)]
+pub struct Services {
+ pub postgres: PgPool,
+ pub cache: RedisManager,
+ pub jetstream: Context,
+}
+
+pub struct AppState {
+ pub services: Services,
+ pub app_config: LocalConfig,
+}
+
+impl AppState {
+ pub async fn create(
+ services: Services,
+ configuration: &Configuration,
+ ) -> Result<AppHandle, AppError> {
+ let local_config: LocalConfig = serde_json::from_value(configuration.misc.clone())?;
+
+ Ok(AppHandle(Arc::new(Self {
+ services,
+ app_config: local_config,
+ })))
+ }
+}