1
0
mirror of https://github.com/actix/examples synced 2025-02-20 08:20:32 +01:00

resolved formatting

This commit is contained in:
dowwie 2020-01-31 07:21:39 -05:00
parent da72aef69c
commit 04cebf6899
4 changed files with 19 additions and 23 deletions

View File

@ -1,6 +1,6 @@
mod config { mod config {
use serde::Deserialize;
pub use ::config::ConfigError; pub use ::config::ConfigError;
use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Config { pub struct Config {
pub server_addr: String, pub server_addr: String,
@ -49,7 +49,9 @@ mod errors {
fn error_response(&self) -> HttpResponse { fn error_response(&self) -> HttpResponse {
match *self { match *self {
MyError::NotFound => HttpResponse::NotFound().finish(), MyError::NotFound => HttpResponse::NotFound().finish(),
MyError::PoolError(ref err) => HttpResponse::InternalServerError().body(err.to_string()), MyError::PoolError(ref err) => {
HttpResponse::InternalServerError().body(err.to_string())
}
_ => HttpResponse::InternalServerError().finish(), _ => HttpResponse::InternalServerError().finish(),
} }
} }
@ -108,9 +110,8 @@ mod handlers {
use actix_web::{web, App, HttpServer}; use actix_web::{web, App, HttpServer};
use dotenv::dotenv; use dotenv::dotenv;
use handlers::add_user; use handlers::add_user;
use tokio_postgres::NoTls;
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{signal, SignalKind};
use tokio_postgres::NoTls;
#[actix_rt::main] #[actix_rt::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {

View File

@ -92,13 +92,11 @@ async fn main() -> io::Result<()> {
_ => HttpResponse::NotFound(), _ => HttpResponse::NotFound(),
}), }),
) )
.service(web::resource("/error").to(|| { .service(web::resource("/error").to(|| async {
async {
error::InternalError::new( error::InternalError::new(
io::Error::new(io::ErrorKind::Other, "test"), io::Error::new(io::ErrorKind::Other, "test"),
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
) )
}
})) }))
// static files // static files
.service(fs::Files::new("/static", "static").show_files_listing()) .service(fs::Files::new("/static", "static").show_files_listing())

View File

@ -30,13 +30,11 @@ async fn main() -> std::io::Result<()> {
res res
}) })
}) })
.service(web::resource("/login").to(|| { .service(web::resource("/login").to(|| async {
async {
"You are on /login. Go to src/redirect.rs to change this behavior." "You are on /login. Go to src/redirect.rs to change this behavior."
}
})) }))
.service(web::resource("/").to(|| { .service(web::resource("/").to(|| async {
async { "Hello, middleware! Check the console where the server is run." } "Hello, middleware! Check the console where the server is run."
})) }))
}) })
.bind("127.0.0.1:8080")? .bind("127.0.0.1:8080")?

View File

@ -1,9 +1,8 @@
use std::{sync::mpsc, thread};
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
use futures::executor; use futures::executor;
use std::{sync::mpsc, thread};
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{signal, SignalKind};
#[get("/hello")] #[get("/hello")]
async fn hello() -> &'static str { async fn hello() -> &'static str {
"Hello world!" "Hello world!"