From 769f5cb1298be647a616463a66129e4aad945da8 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:44:48 +0000 Subject: [PATCH] Reorganise code by day --- src/cal/day00.rs | 15 +++++++++++++++ src/cal/mod.rs | 6 ++++++ src/main.rs | 16 ++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/cal/day00.rs create mode 100644 src/cal/mod.rs diff --git a/src/cal/day00.rs b/src/cal/day00.rs new file mode 100644 index 0000000..2d55dde --- /dev/null +++ b/src/cal/day00.rs @@ -0,0 +1,15 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::get, Router}; + +pub(crate) fn router() -> Router { + Router::new() + .route("/", get(hello_world)) + .route("/-1/error", get(fake_error)) +} + +async fn hello_world() -> impl IntoResponse { + "Hello, world!" +} + +async fn fake_error() -> impl IntoResponse { + StatusCode::INTERNAL_SERVER_ERROR +} diff --git a/src/cal/mod.rs b/src/cal/mod.rs new file mode 100644 index 0000000..a9dda0c --- /dev/null +++ b/src/cal/mod.rs @@ -0,0 +1,6 @@ +mod day00; + +pub(crate) fn router() -> axum::Router { + axum::Router::new() + .nest("/", day00::router()) +} diff --git a/src/main.rs b/src/main.rs index c36b6b8..e54ff99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,6 @@ -use axum::{http::StatusCode, response::IntoResponse, routing::get, Router}; - -async fn hello_world() -> impl IntoResponse { - "Hello, world!" -} - -async fn fake_error() -> impl IntoResponse { - StatusCode::INTERNAL_SERVER_ERROR -} +mod cal; #[shuttle_runtime::main] async fn main() -> shuttle_axum::ShuttleAxum { - let router = Router::new() - .route("/", get(hello_world)) - .route("/-1/error", get(fake_error)); - - Ok(router.into()) + Ok(axum::Router::new().nest("/", cal::router()).into()) }