Skip to content

Commit

Permalink
refactor(bot): use match expression for router
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Apr 10, 2023
1 parent 7c3752c commit 4a10529
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ impl App {
let (Parts { uri, method, headers, .. }, body) = req.into_parts();
let path = uri.path();

if method == Method::GET && path == "/healthz" {
log::info!("Health check pinged");
return Ok(Response::new(Body::empty()));
}

if method != Method::POST {
log::error!("Unexpected `{method}` request received");
return Err(StatusCode::METHOD_NOT_ALLOWED);
}

if path != "/discord" {
log::error!("Unexpected `POST {path}` request received");
return Err(StatusCode::NOT_FOUND);
match method {
Method::GET | Method::HEAD => match path {
"/health" => {
log::info!("Health check pinged");
return Ok(Response::new(Body::empty()));
}
_ => {
log::error!("Unexpected `{method} {path}` request received");
return Err(StatusCode::NOT_FOUND);
}
}
Method::POST => match path {
"/discord" => (),
_ => {
log::error!("Unexpected `POST {path}` request received");
return Err(StatusCode::NOT_FOUND);
}
}
_ => {
log::error!("Unexpected `{method} {path}` request received");
return Err(StatusCode::METHOD_NOT_ALLOWED);
}
}

// Retrieve security headers
Expand Down

0 comments on commit 4a10529

Please sign in to comment.