1use deadpool_redis::{Config, Pool, Runtime};
2
3use std::env;
4use std::sync::Arc;
5
6mod contact;
7mod core;
8mod organization;
9
10pub struct DingTalk {
11 pub appid: String,
12 pub app_secret: String,
13 pub client: reqwest::Client,
14 pub rdb: Arc<Pool>,
15}
16
17impl DingTalk {
18 pub fn new(appid: String, app_secret: String) -> Self {
25 let cfg =
26 env::var("REDIS_URL").unwrap_or_else(|_| "redis://:@127.0.0.1:6379/1".to_string());
27
28 let pool_config = Config::from_url(cfg);
29 let pool = match pool_config.create_pool(Some(Runtime::Tokio1)) {
30 Ok(pool) => pool,
31 Err(e) => panic!("Failed to create Redis pool: {}", e),
32 };
33
34 DingTalk {
35 appid,
36 app_secret,
37 client: reqwest::Client::new(),
38 rdb: Arc::new(pool),
39 }
40 }
41}