-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project structure major refactor - Splitting things in modules
- Loading branch information
Showing
9 changed files
with
57 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
use actix_web::dev::Server; | ||
use actix_web::{web, App, HttpResponse, HttpServer}; | ||
use std::net::TcpListener; | ||
|
||
async fn health_check() -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
} | ||
|
||
#[derive(serde::Deserialize)] | ||
struct FormData { | ||
#[allow(dead_code)] | ||
email: String, | ||
#[allow(dead_code)] | ||
name: String, | ||
} | ||
|
||
async fn subscribe(_form: web::Form<FormData>) -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
} | ||
|
||
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> { | ||
let server = HttpServer::new(|| { | ||
App::new() | ||
.route("/health_check", web::get().to(health_check)) | ||
.route("/subscriptions", web::post().to(subscribe)) | ||
}) | ||
.listen(listener)? | ||
.run(); | ||
Ok(server) | ||
} | ||
pub mod configuration; | ||
pub mod routes; | ||
pub mod startup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use actix_web::HttpResponse; | ||
|
||
pub async fn health_check() -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod health_check; | ||
mod subscriptions; | ||
|
||
pub use health_check::*; | ||
pub use subscriptions::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use actix_web::{web, HttpResponse}; | ||
|
||
#[derive(serde::Deserialize)] | ||
pub struct FormData { | ||
#[allow(dead_code)] | ||
email: String, | ||
#[allow(dead_code)] | ||
name: String, | ||
} | ||
|
||
pub async fn subscribe(_form: web::Form<FormData>) -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::net::TcpListener; | ||
|
||
use crate::routes::{health_check, subscribe}; | ||
use actix_web::{dev::Server, web, App, HttpServer}; | ||
|
||
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> { | ||
let server = HttpServer::new(|| { | ||
App::new() | ||
.route("/health_check", web::get().to(health_check)) | ||
.route("/subscriptions", web::post().to(subscribe)) | ||
}) | ||
.listen(listener)? | ||
.run(); | ||
Ok(server) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters