Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
refactor(crate): Move handler to separate (sub)module
Browse files Browse the repository at this point in the history
  • Loading branch information
nain-F49FF806 committed Jun 23, 2023
1 parent f7a5020 commit 877cf3b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 Naian G.
// SPDX-License-Identifier: Apache-2.0
mod router;
mod routes;
mod server;
use server::run_server;

Expand Down
7 changes: 2 additions & 5 deletions src/router.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright 2023 Naian G.
// SPDX-License-Identifier: Apache-2.0
use axum::{Router, routing::get};
use crate::routes::hello_world;

This comment has been minimized.

Copy link
@nain-F49FF806

nain-F49FF806 Jul 11, 2023

Author Owner

hello_world, a submodule of module routes is called here using its path from root crate


pub fn create_router() -> Router {
let app = Router::new().route("/", get(handle_get));
let app = Router::new().route("/", get(hello_world::handle_get));
return app;
}

async fn handle_get() -> String {
"hey".to_owned()
}
6 changes: 6 additions & 0 deletions src/routes/hello_world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2023 Naian G.
// SPDX-License-Identifier: Apache-2.0

pub async fn handle_get() -> String {
"hey".to_owned()
}
4 changes: 4 additions & 0 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2023 Naian G.
// SPDX-License-Identifier: Apache-2.0

pub mod hello_world;

This comment has been minimized.

Copy link
@nain-F49FF806

nain-F49FF806 Jul 11, 2023

Author Owner

routes module defined in the special named file routes/mod.rs can load any other module present in this directory (routes) as submodule.

0 comments on commit 877cf3b

Please sign in to comment.