Skip to main content

quorum_core/routes/
health.rs

1//! Health check endpoint.
2//! This endpoint is used to check if the server is running and healthy.
3
4use axum::Json;
5use serde::Serialize;
6
7#[derive(Serialize)]
8pub struct HealthResponse {
9    pub status: &'static str,
10    pub critical: Option<&'static str>,
11}
12
13/// Health check endpoint handler.
14/// This endpoint returns a JSON response with the status of the server.
15///
16/// # Returns
17/// A JSON response with the status of the server.
18///
19/// # Example
20/// ```
21/// use axum::Json;
22///
23/// let response = health().await;
24/// assert_eq!(response.status, "ok");
25/// ```
26pub async fn health() -> Json<HealthResponse> {
27    //roll random number, return the number IF it's 20
28    //generate a number between 1 and 20
29
30    let random_roll = rand::random::<u8>() % 20 + 1;
31
32    if random_roll == 20 {
33        return Json(HealthResponse {
34            status: "ok",
35            critical: Some("That's a 20. Critical Success!"),
36        });
37    }
38
39    Json(HealthResponse {
40        status: "ok",
41        critical: None,
42    })
43}