-
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.
refactor!: split in modules instead of a single lib file
- Loading branch information
Showing
10 changed files
with
662 additions
and
43 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,2 @@ | ||
|
||
|
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,33 +1,3 @@ | ||
use actix_web::{dev::Server, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; | ||
use std::net::TcpListener; | ||
|
||
async fn greet(req: HttpRequest) -> impl Responder { | ||
let name = req.match_info().get("name").unwrap_or("World"); | ||
format!("Hello {name}!") | ||
} | ||
|
||
async fn health_check() -> impl Responder { | ||
HttpResponse::Ok() | ||
} | ||
|
||
#[derive(serde::Deserialize)] | ||
struct FormData { | ||
email: String, | ||
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 configurations; | ||
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, Responder}; | ||
|
||
pub async fn health_check() -> impl Responder { | ||
HttpResponse::Ok() | ||
} |
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,11 @@ | ||
use actix_web::{web, HttpResponse}; | ||
|
||
#[derive(serde::Deserialize)] | ||
pub struct FormData { | ||
email: String, | ||
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,17 @@ | ||
use std::net::TcpListener; | ||
|
||
use actix_web::{dev::Server, web, App, HttpServer}; | ||
|
||
use crate::routes::{health_check, subscribe}; | ||
|
||
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