change String to &'a str'

This commit is contained in:
2019-11-26 00:52:11 +08:00
parent 96fb1e701b
commit c66f563c2e

View File

@@ -13,27 +13,31 @@ use crypto::{
pub const OSS_VERB_GET: &str = "GET";
// https://help.aliyun.com/document_detail/31952.html
pub struct OSSClient {
pub endpoint: String,
pub access_key_id: String,
pub access_key_secret: String,
pub struct OSSClient<'a> {
pub endpoint: &'a str,
pub access_key_id: &'a str,
pub access_key_secret: &'a str,
}
impl OSSClient {
pub fn new(endpoint: &str, access_key_id: &str, access_key_secret: &str) -> OSSClient {
impl<'a> OSSClient<'a> {
pub fn new(endpoint: &'a str, access_key_id: &'a str, access_key_secret: &'a str) -> OSSClient<'a> {
OSSClient {
endpoint: endpoint.to_string(),
access_key_id: access_key_id.to_string(),
access_key_secret: access_key_secret.to_string(),
endpoint: endpoint,
access_key_id: access_key_id,
access_key_secret: access_key_secret,
}
}
pub fn generate_signed_get_url(&self, bucket_name: &str, key: &str, expire_in_seconds: u64) -> String {
self.generate_signed_url(OSS_VERB_GET, bucket_name, key, expire_in_seconds, true)
}
pub fn generate_signed_url(&self, verb: &str, bucket_name: &str, key: &str, expire_in_seconds: u64, is_https: bool) -> String {
let mut signed_url = String::new();
signed_url.push_str(if is_https { "https://" } else { "http://" });
signed_url.push_str(bucket_name);
signed_url.push_str(".");
signed_url.push_str(self.endpoint.as_str());
signed_url.push_str(self.endpoint);
signed_url.push_str("/");
signed_url.push_str(key);
@@ -43,7 +47,7 @@ impl OSSClient {
signed_url.push_str("?Expires=");
signed_url.push_str(expire_secs.to_string().as_str());
signed_url.push_str("&OSSAccessKeyId=");
signed_url.push_str(&urlencoding::encode(self.access_key_id.as_str()));
signed_url.push_str(&urlencoding::encode(self.access_key_id));
signed_url.push_str("&Signature=");
let to_be_signed = get_to_be_signed(verb, expire_secs, bucket_name, key);