Add a better structure in the project

This commit is contained in:
2025-08-15 18:02:30 -04:00
parent 985443ca91
commit 611301dfda
10 changed files with 178 additions and 7 deletions

View File

@@ -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,
})
}
}

View File

@@ -1,4 +1,4 @@
// src/health.rs
// src/handlers/health/health.rs
use axum::Json;
use axum::http::StatusCode;

View File

@@ -0,0 +1,3 @@
// src/handlers/health/mod.rs
pub mod health;

3
src/handlers/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
// src/handlers/mod.rs
pub mod health;

View File

@@ -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

View 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
View File

@@ -0,0 +1,4 @@
// src/routes/health/mod.rs
pub mod health;

3
src/routes/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
// src/routes/mod.rs
pub mod health;