Skip to main content

u_sdk/oss/
mod.rs

1//! 阿里云oss sdk
2
3pub mod bucket;
4pub mod object;
5pub mod region;
6pub mod service;
7
8mod error;
9
10pub use error::Error;
11use std::sync::Arc;
12
13pub(crate) mod sign_v4;
14pub(crate) mod utils;
15
16use crate::credentials::CredentialsProvider;
17use bon::bon;
18
19pub struct Client {
20    credentials_provider: Arc<dyn CredentialsProvider>,
21    endpoint: String,
22    region: String,
23    bucket: String,
24    http_client: reqwest::Client,
25}
26
27/// 创建oss客户端
28#[bon]
29impl Client {
30    /// region和endpoint:<https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints>
31    #[builder(on(String, into))]
32    pub fn new(
33        credentials_provider: Arc<dyn CredentialsProvider>,
34        endpoint: String,
35        region: String,
36        bucket: String,
37    ) -> Self {
38        Self {
39            credentials_provider,
40            endpoint,
41            region,
42            bucket,
43            http_client: reqwest::Client::new(),
44        }
45    }
46    pub fn bucket(&self) -> &str {
47        &self.bucket
48    }
49
50    pub fn region(&self) -> &str {
51        &self.region
52    }
53
54    pub fn endpoint(&self) -> &str {
55        &self.endpoint
56    }
57}