forked from Trustless-OSS/Toss-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.rs
More file actions
37 lines (32 loc) · 869 Bytes
/
Copy pathstate.rs
File metadata and controls
37 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::sync::Arc;
use reqwest::Client;
use crate::{
config::Config,
error::AppError,
infra::{cache::Cache, db, queue::QueueInfra, redis},
};
#[derive(Clone)]
pub struct AppState {
pub config: Arc<Config>,
pub db: toasty::Db,
pub redis: Option<redis::RedisClient>,
pub http_client: Client,
pub cache: Cache,
pub queue: QueueInfra,
}
impl AppState {
pub async fn new(config: Config) -> Result<Self, AppError> {
let db = db::connect(&config.database_url).await?;
let redis = Some(redis::build_client(&config.redis_url)?);
let cache = Cache::new(redis.clone());
let queue = QueueInfra::new(redis.clone());
Ok(Self {
config: Arc::new(config),
db,
redis,
http_client: Client::new(),
cache,
queue,
})
}
}