open_lark/core/
config.rs

1use std::{collections::HashMap, sync::Arc, time::Duration};
2use tokio::sync::Mutex;
3
4use crate::core::{
5    app_ticket_manager::AppTicketManager,
6    constants::{AppType, FEISHU_BASE_URL},
7    token_manager::TokenManager,
8};
9
10#[derive(Debug, Clone)]
11pub struct Config {
12    pub app_id: String,
13    pub app_secret: String,
14    /// 域名, 默认为 <https://open.feishu.cn>
15    pub base_url: String,
16    pub enable_token_cache: bool,
17    /// 应用类型, 默认为自建应用
18    pub app_type: AppType,
19    pub http_client: reqwest::Client,
20    /// 客户端超时时间, 默认永不超时
21    pub req_timeout: Option<Duration>,
22    pub header: HashMap<String, String>,
23    /// Token 管理器
24    pub token_manager: Arc<Mutex<TokenManager>>,
25    /// App Ticket 管理器  
26    pub app_ticket_manager: Arc<Mutex<AppTicketManager>>,
27}
28
29impl Default for Config {
30    fn default() -> Self {
31        Self {
32            app_id: "".to_string(),
33            app_secret: "".to_string(),
34            base_url: FEISHU_BASE_URL.to_string(),
35            enable_token_cache: true,
36            app_type: AppType::SelfBuild,
37            http_client: reqwest::Client::new(),
38            req_timeout: None,
39            header: Default::default(),
40            token_manager: Arc::new(Mutex::new(TokenManager::new())),
41            app_ticket_manager: Arc::new(Mutex::new(AppTicketManager::new())),
42        }
43    }
44}