style: code style

This commit is contained in:
2020-08-02 23:11:56 +08:00
parent 787ca083d9
commit ee5a31b9c5
2 changed files with 10 additions and 14 deletions

View File

@@ -16,5 +16,5 @@ rust-crypto = "0.2.36"
urlencoding = "1.0.0" urlencoding = "1.0.0"
base64 = "0.11.0" base64 = "0.11.0"
reqwest = "0.10.0" reqwest = "0.10.0"
rust_util="0.2.0" rust_util="0.6.3"
json = "0.12.0" json = "0.12.0"

View File

@@ -1,22 +1,20 @@
#[macro_use]
extern crate rust_util;
use std::{ use std::{
io::Read, io::Read,
fs::{ self, File, }, fs::{ self, File },
env, env,
path::PathBuf, path::PathBuf,
io::{ Error, ErrorKind, }, io::{ Error, ErrorKind },
}; };
use crypto::{ use crypto::{
mac::{ Mac, MacResult, }, mac::{ Mac, MacResult },
hmac::Hmac, hmac::Hmac,
sha1::Sha1, sha1::Sha1,
}; };
use reqwest::Response; use reqwest::Response;
use rust_util::{ use rust_util::{ XResult, new_box_ioerror, util_time::get_current_secs };
iff,
XResult,
new_box_ioerror,
util_time::get_current_secs,
};
pub const OSS_VERB_GET: &str = "GET"; pub const OSS_VERB_GET: &str = "GET";
pub const OSS_VERB_PUT: &str = "PUT"; pub const OSS_VERB_PUT: &str = "PUT";
@@ -94,7 +92,7 @@ impl OSSClient {
pub async fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult<Response> { pub async fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult<Response> {
let put_url = self.generate_signed_put_url(bucket_name, key, expire_in_seconds); let put_url = self.generate_signed_put_url(bucket_name, key, expire_in_seconds);
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let mut v = Vec::new(); let mut v = vec![];
let mut file = file; let mut file = file;
file.read_to_end(&mut v)?; file.read_to_end(&mut v)?;
Ok(client.put(&put_url).body(v).send().await?) Ok(client.put(&put_url).body(v).send().await?)
@@ -121,9 +119,7 @@ impl OSSClient {
let response = reqwest::get(&get_url).await?; let response = reqwest::get(&get_url).await?;
match response.status().as_u16() { match response.status().as_u16() {
404_u16 => Ok(None), 404_u16 => Ok(None),
200_u16 => { 200_u16 => Ok(Some(response.bytes().await?.as_ref().to_vec())),
Ok(Some(response.bytes().await?.as_ref().to_vec()))
},
_ => Err(new_box_ioerror(&format!("Error in read: {}/{}, returns: {:?}", bucket_name, key, response)) as Box<dyn std::error::Error>), _ => Err(new_box_ioerror(&format!("Error in read: {}/{}, returns: {:?}", bucket_name, key, response)) as Box<dyn std::error::Error>),
} }
} }