mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
Run rustfmt
This commit is contained in:
parent
8f1c0a85cf
commit
046604f286
@ -98,8 +98,7 @@ mod handlers {
|
|||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let user_info: User = user.into_inner();
|
let user_info: User = user.into_inner();
|
||||||
|
|
||||||
let client: Client =
|
let client: Client = db_pool.get().await.map_err(MyError::PoolError)?;
|
||||||
db_pool.get().await.map_err(MyError::PoolError)?;
|
|
||||||
|
|
||||||
let new_user = db::add_user(&client, user_info).await?;
|
let new_user = db::add_user(&client, user_info).await?;
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, client::{Client, Connector}};
|
use actix_web::{
|
||||||
|
client::{Client, Connector},
|
||||||
|
web, App, HttpRequest, HttpResponse, HttpServer,
|
||||||
|
};
|
||||||
use openssl::ssl::{SslConnector, SslMethod};
|
use openssl::ssl::{SslConnector, SslMethod};
|
||||||
|
|
||||||
|
|
||||||
async fn index(_req: HttpRequest) -> HttpResponse {
|
async fn index(_req: HttpRequest) -> HttpResponse {
|
||||||
let builder = SslConnector::builder(SslMethod::tls()).unwrap();
|
let builder = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||||
|
|
||||||
let client = Client::build()
|
let client = Client::build()
|
||||||
.connector(Connector::new().ssl(builder.build()).finish())
|
.connector(Connector::new().ssl(builder.build()).finish())
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
let now = std::time::Instant::now();
|
let now = std::time::Instant::now();
|
||||||
let payload =
|
let payload =
|
||||||
client
|
client
|
||||||
.get("https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg")
|
.get("https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg")
|
||||||
@ -21,22 +23,20 @@ async fn index(_req: HttpRequest) -> HttpResponse {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("awc time elapsed while reading bytes into memory: {} ms", now.elapsed().as_millis());
|
println!(
|
||||||
|
"awc time elapsed while reading bytes into memory: {} ms",
|
||||||
|
now.elapsed().as_millis()
|
||||||
|
);
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok().content_type("image/jpeg").body(payload)
|
||||||
.content_type("image/jpeg")
|
|
||||||
.body(payload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let port = 3000;
|
let port = 3000;
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| App::new().service(web::resource("/").to(index)))
|
||||||
App::new()
|
.bind(("0.0.0.0", port))?
|
||||||
.service(web::resource("/").to(index))
|
.run()
|
||||||
})
|
.await
|
||||||
.bind(("0.0.0.0", port))?
|
|
||||||
.run()
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,8 @@ async fn again() -> impl Responder {
|
|||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
println!("Starting actix-web server");
|
println!("Starting actix-web server");
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| App::new().service(index).service(again))
|
||||||
App::new()
|
.bind("0.0.0.0:5000")?
|
||||||
.service(index)
|
.run()
|
||||||
.service(again)
|
.await
|
||||||
})
|
|
||||||
.bind("0.0.0.0:5000")?
|
|
||||||
.run()
|
|
||||||
.await
|
|
||||||
}
|
}
|
@ -33,27 +33,26 @@ impl User {
|
|||||||
fn products(&self, context: &Context) -> Vec<Product> {
|
fn products(&self, context: &Context) -> Vec<Product> {
|
||||||
let mut conn = context.dbpool.get().unwrap();
|
let mut conn = context.dbpool.get().unwrap();
|
||||||
|
|
||||||
conn
|
conn.prep_exec(
|
||||||
.prep_exec(
|
"select * from product where user_id=:user_id",
|
||||||
"select * from product where user_id=:user_id",
|
params! {
|
||||||
params! {
|
"user_id" => &self.id
|
||||||
"user_id" => &self.id
|
},
|
||||||
},
|
)
|
||||||
)
|
.map(|result| {
|
||||||
.map(|result| {
|
result
|
||||||
result
|
.map(|x| x.unwrap())
|
||||||
.map(|x| x.unwrap())
|
.map(|mut row| {
|
||||||
.map(|mut row| {
|
let (id, user_id, name, price) = from_row(row);
|
||||||
let (id, user_id, name, price) = from_row(row);
|
Product {
|
||||||
Product {
|
id,
|
||||||
id,
|
user_id,
|
||||||
user_id,
|
name,
|
||||||
name,
|
price,
|
||||||
price,
|
}
|
||||||
}
|
})
|
||||||
})
|
.collect()
|
||||||
.collect()
|
})
|
||||||
})
|
.unwrap()
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
|||||||
use futures::executor;
|
use futures::executor;
|
||||||
use std::{sync::mpsc, thread};
|
use std::{sync::mpsc, thread};
|
||||||
|
|
||||||
|
|
||||||
#[get("/hello")]
|
#[get("/hello")]
|
||||||
async fn hello() -> &'static str {
|
async fn hello() -> &'static str {
|
||||||
"Hello world!"
|
"Hello world!"
|
||||||
|
Loading…
Reference in New Issue
Block a user