refactor: split routes into multiple files
This commit is contained in:
parent
a7f85a5d3a
commit
f078537aab
3 changed files with 16 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
use axum::{routing::get, Router};
|
||||
use axum::Router;
|
||||
use clap::Parser;
|
||||
|
||||
mod routes;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version, about)]
|
||||
struct Args {
|
||||
|
@ -13,7 +15,7 @@ struct Args {
|
|||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
|
||||
let app = Router::new().nest("/", routes::router());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind((args.host, args.port)).await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
|
5
src/routes/healthcheck.rs
Normal file
5
src/routes/healthcheck.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use axum::{routing::get, Router};
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new().route("/", get(|| async {"Ok"}))
|
||||
}
|
7
src/routes/mod.rs
Normal file
7
src/routes/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use axum::Router;
|
||||
|
||||
mod healthcheck;
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new().nest("/healthcheck", healthcheck::router())
|
||||
}
|
Loading…
Reference in a new issue