1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

Use captured args in format string (#558)

This commit is contained in:
Yuri Astrakhan
2022-06-07 22:53:38 -04:00
committed by GitHub
parent 912de4aa46
commit db5f00e771
37 changed files with 57 additions and 60 deletions

View File

@ -62,7 +62,7 @@ async fn handle_post_2(
/// Request and POST Params
async fn handle_post_3(req: HttpRequest, params: web::Form<MyParams>) -> impl Responder {
println!("Handling POST request: {:?}", req);
println!("Handling POST request: {req:?}");
HttpResponse::Ok()
.content_type("text/plain")

View File

@ -81,9 +81,9 @@ async fn main() -> std::io::Result<()> {
let aws_s3_bucket_name =
env::var("AWS_S3_BUCKET_NAME").expect("AWS_S3_BUCKET_NAME must be set");
log::info!("aws_access_key_id: {}", aws_access_key_id);
log::info!("aws_secret_access_key: {}", aws_secret_access_key);
log::info!("aws_s3_bucket_name: {}", aws_s3_bucket_name);
log::info!("aws_access_key_id: {aws_access_key_id}");
log::info!("aws_secret_access_key: {aws_secret_access_key}");
log::info!("aws_s3_bucket_name: {aws_s3_bucket_name}");
std::fs::create_dir_all("./tmp").unwrap();

View File

@ -24,10 +24,9 @@ impl Client {
pub fn url(&self, key: &str) -> String {
format!(
"https://{}.s3.{}.amazonaws.com/{}",
"https://{}.s3.{}.amazonaws.com/{key}",
std::env::var("AWS_S3_BUCKET_NAME").unwrap(),
std::env::var("AWS_REGION").unwrap(),
key
)
}

View File

@ -39,7 +39,7 @@ impl Tmpfile {
fn new(filename: &str) -> Tmpfile {
Tmpfile {
name: filename.to_string(),
tmp_path: format!("./tmp/{}", filename),
tmp_path: format!("./tmp/{filename}"),
s3_key: "".to_string(),
s3_url: "".to_string(),
}
@ -51,7 +51,7 @@ impl Tmpfile {
}
async fn s3_upload(&mut self, s3_upload_key: String) {
let key = format!("{}{}", &s3_upload_key, &self.name);
let key = format!("{s3_upload_key}{}", &self.name);
self.s3_key = key.clone();
let url: String = Client::new().put_object(&self.tmp_path, &key.clone()).await;
self.s3_url = url;

View File

@ -14,7 +14,7 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
let filename = content_disposition
.get_filename()
.map_or_else(|| Uuid::new_v4().to_string(), sanitize_filename::sanitize);
let filepath = format!("./tmp/{}", filename);
let filepath = format!("./tmp/{filename}");
// File::create is blocking operation, use threadpool
let mut f = web::block(|| std::fs::File::create(filepath)).await??;