1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02: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 {
use serde::Deserialize;
pub use ::config::ConfigError;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct Config {
pub server_addr: String,
@ -49,7 +49,9 @@ mod errors {
fn error_response(&self) -> HttpResponse {
match *self {
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(),
}
}
@ -98,7 +100,7 @@ mod handlers {
let client: Client =
db_pool.get().await.map_err(|err| MyError::PoolError(err))?;
let new_user = db::add_user(&client, user_info).await?;
Ok(HttpResponse::Ok().json(new_user))
@ -108,9 +110,8 @@ mod handlers {
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
use handlers::add_user;
use tokio_postgres::NoTls;
use tokio::signal::unix::{signal, SignalKind};
use tokio_postgres::NoTls;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
@ -129,14 +130,14 @@ async fn main() -> std::io::Result<()> {
println!("Server running at http://{}/", config.server_addr);
let srv = server.clone();
let mut stream = signal(SignalKind::interrupt())?;
let mut stream = signal(SignalKind::interrupt())?;
actix_rt::spawn(async move {
loop {
stream.recv().await;
println!("\nSIGINT Received. Stopping server.\n");
srv.stop(true).await;
}
});
});
server.await
}