refactor: restructure project
This commit is contained in:
parent
699f8733e2
commit
89ea0995bb
9 changed files with 57 additions and 44 deletions
0
src/configuration.rs
Normal file
0
src/configuration.rs
Normal file
32
src/lib.rs
32
src/lib.rs
|
|
@ -1,29 +1,3 @@
|
|||
#![allow(unused)]
|
||||
use axum::extract::{Path, Query};
|
||||
use axum::http::{Method, Uri};
|
||||
use axum::response::{Html, IntoResponse, Response};
|
||||
use axum::routing::{get, get_service, post, IntoMakeService};
|
||||
use axum::serve::Serve;
|
||||
use axum::{middleware, Json, Router};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct FormData {
|
||||
email: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
/// API routing
|
||||
pub fn app() -> Router {
|
||||
Router::new()
|
||||
.route("/health_check", get(|| async {}))
|
||||
.route("/subscriptions", post(|| async {}))
|
||||
}
|
||||
|
||||
/// Start the server
|
||||
pub fn run(listener: TcpListener) -> Serve<IntoMakeService<Router>, Router> {
|
||||
axum::serve(listener, app().into_make_service())
|
||||
}
|
||||
pub mod configuration;
|
||||
pub mod routes;
|
||||
pub mod startup;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use learn_axum::run;
|
||||
use tokio::net::TcpListener;
|
||||
use learn_axum::startup;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let addr = format!("127.0.0.1:{}", "3000");
|
||||
let listener = TcpListener::bind(addr).await.unwrap(); //.expect("Unable to bind to port");
|
||||
run(listener).await.unwrap();
|
||||
startup::run(listener).await.unwrap();
|
||||
}
|
||||
|
|
|
|||
6
src/routes/health_check.rs
Normal file
6
src/routes/health_check.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
|
||||
pub fn routes_health_check() -> Router {
|
||||
Router::new().route("/health_check", get(|| async {}))
|
||||
}
|
||||
5
src/routes/mod.rs
Normal file
5
src/routes/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod health_check;
|
||||
mod subscriptions;
|
||||
|
||||
pub use health_check::*;
|
||||
pub use subscriptions::*;
|
||||
12
src/routes/subscriptions.rs
Normal file
12
src/routes/subscriptions.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct FormData {
|
||||
email: String,
|
||||
name: String,
|
||||
}
|
||||
pub fn routes_subscriptions() -> Router {
|
||||
Router::new().route("/subscriptions", get(|| async {}))
|
||||
}
|
||||
16
src/startup.rs
Normal file
16
src/startup.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use axum::routing::IntoMakeService;
|
||||
use axum::serve::Serve;
|
||||
use axum::Router;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
/// API routing
|
||||
pub fn app() -> Router {
|
||||
Router::new()
|
||||
.merge(crate::routes::routes_health_check())
|
||||
.merge(crate::routes::routes_subscriptions())
|
||||
}
|
||||
|
||||
/// Start the server
|
||||
pub fn run(listener: TcpListener) -> Serve<IntoMakeService<Router>, Router> {
|
||||
axum::serve(listener, app().into_make_service())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue