Add a better structure in the project
This commit is contained in:
@@ -7,7 +7,7 @@ use std::str::FromStr;
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
pub bind_address: SocketAddr,
|
||||
pub database_url: Option<String>,
|
||||
// pub database_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -24,11 +24,11 @@ impl Config {
|
||||
return Err("In no-auth mode, BIND_ADDRESS must be 127.0.0.1".to_string());
|
||||
}
|
||||
|
||||
let database_url = env::var("DATABASE_URL").ok();
|
||||
// let database_url = env::var("DATABASE_URL").ok();
|
||||
|
||||
Ok(Self {
|
||||
bind_address,
|
||||
database_url,
|
||||
// database_url,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// src/health.rs
|
||||
// src/handlers/health/health.rs
|
||||
|
||||
use axum::Json;
|
||||
use axum::http::StatusCode;
|
||||
3
src/handlers/health/mod.rs
Normal file
3
src/handlers/health/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/handlers/health/mod.rs
|
||||
|
||||
pub mod health;
|
||||
3
src/handlers/mod.rs
Normal file
3
src/handlers/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/handlers/mod.rs
|
||||
|
||||
pub mod health;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use axum::Router;
|
||||
use dotenvy::dotenv;
|
||||
use tokio::signal;
|
||||
use tower_http::trace::TraceLayer;
|
||||
@@ -10,7 +10,8 @@ use tracing::{error, info};
|
||||
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
||||
|
||||
mod config;
|
||||
mod health;
|
||||
mod handlers;
|
||||
mod routes;
|
||||
|
||||
use config::Config;
|
||||
|
||||
@@ -41,7 +42,8 @@ async fn main() {
|
||||
|
||||
// Build the Axum router
|
||||
let app = Router::new()
|
||||
.route("/health", get(health::health))
|
||||
// .nest("/health", routes::health::health::health_routes())
|
||||
.nest("/health", routes::health::health::health_routes())
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
// Run the server
|
||||
|
||||
9
src/routes/health/health.rs
Normal file
9
src/routes/health/health.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// src/routes/health/health.rs
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
|
||||
use crate::handlers::health::health::health;
|
||||
|
||||
pub fn health_routes() -> Router {
|
||||
Router::new().route("/", get(health))
|
||||
}
|
||||
4
src/routes/health/mod.rs
Normal file
4
src/routes/health/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
// src/routes/health/mod.rs
|
||||
|
||||
pub mod health;
|
||||
|
||||
3
src/routes/mod.rs
Normal file
3
src/routes/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/routes/mod.rs
|
||||
|
||||
pub mod health;
|
||||
Reference in New Issue
Block a user