pub struct Config {
pub app_id: String,
pub app_secret: String,
pub app_type: AppType,
pub enable_token_cache: bool,
pub base_url: String,
pub timeout: Duration,
pub retry_count: u32,
pub enable_log: bool,
pub headers: HashMap<String, String>,
/* private fields */
}Expand description
🔧 OpenLark客户端配置
支持从环境变量自动加载配置
§环境变量
OPENLARK_APP_ID: 应用ID(必需)OPENLARK_APP_SECRET: 应用密钥(必需)OPENLARK_APP_TYPE: 应用类型(可选:self_build / marketplace,默认 self_build)OPENLARK_BASE_URL: API基础URL(可选,默认:https://open.feishu.cn,国际版 Lark 使用https://open.larksuite.com)OPENLARK_ENABLE_TOKEN_CACHE: 是否允许自动获取 token(可选,默认 true)
§示例
use openlark_client::Config;
// 从环境变量创建配置
let config = Config::from_env();
// 手动构建配置
let config = Config::builder()
.app_id("your_app_id")
.app_secret("your_app_secret")
.base_url("https://open.feishu.cn") // 默认值,国际版 Lark 使用 https://open.larksuite.com
.build();Fields§
§app_id: String🆔 飞书应用ID
app_secret: String🔑 飞书应用密钥
app_type: AppType🏷️ 应用类型(自建 / 商店)
enable_token_cache: bool🔐 是否允许 SDK 自动获取 token(通过 openlark-core 的 TokenProvider)
base_url: String🌐 API基础URL
timeout: Duration⏱️ 请求超时时间
retry_count: u32🔄 默认重试次数
enable_log: bool📝 是否启用日志记录
headers: HashMap<String, String>📋 自定义HTTP headers
Implementations§
Source§impl Config
impl Config
Sourcepub fn load_from_env(&mut self)
pub fn load_from_env(&mut self)
📥 从环境变量加载配置到当前实例
只设置存在且非空的环境变量
Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
🏗️ 创建配置构建器
Sourcepub fn add_header<K, V>(&mut self, key: K, value: V)
pub fn add_header<K, V>(&mut self, key: K, value: V)
🔧 添加自定义HTTP header
Sourcepub fn clear_headers(&mut self)
pub fn clear_headers(&mut self)
🧹 清除所有自定义headers
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
🔍 检查配置是否完整(可用于API调用)
Sourcepub fn summary(&self) -> ConfigSummary
pub fn summary(&self) -> ConfigSummary
📋 获取配置摘要(不包含敏感信息)
Sourcepub fn update_with(&mut self, other: &Config)
pub fn update_with(&mut self, other: &Config)
🔄 更新配置,只更新非空字段
Sourcepub fn build_core_config(&self) -> Config
pub fn build_core_config(&self) -> Config
🔧 构建底层 core 配置(不含 TokenProvider)
Sourcepub fn build_core_config_with_token_provider(&self) -> Config
pub fn build_core_config_with_token_provider(&self) -> Config
🔧 构建带有默认 TokenProvider 的 core 配置
Sourcepub fn get_or_build_core_config(&self) -> Config
pub fn get_or_build_core_config(&self) -> Config
🔧 获取或构建 core 配置
Sourcepub fn get_or_build_core_config_with_token_provider(&self) -> Config
pub fn get_or_build_core_config_with_token_provider(&self) -> Config
🔧 获取或构建带有 TokenProvider 的 core 配置
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl !UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more