refactor: ♻️ global signals removed
refactor: ♻️ type restrictions for statuses
This commit is contained in:
parent
adbbd52b3e
commit
a6e95affab
2 changed files with 78 additions and 50 deletions
|
@ -1,8 +1,20 @@
|
|||
use crate::AppState;
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tower_http::cors::CorsLayer;
|
||||
use rand::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
enum ServerStatus{
|
||||
Alive,
|
||||
Unstable,
|
||||
Dead,
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Serialize,Deserialize)]
|
||||
enum CoinStatus{
|
||||
Tail,
|
||||
Head,
|
||||
}
|
||||
|
||||
pub async fn routing(State(state): State<AppState>) -> Router {
|
||||
Router::new()
|
||||
|
@ -14,7 +26,7 @@ pub async fn routing(State(state): State<AppState>) -> Router {
|
|||
|
||||
async fn alive() -> impl IntoResponse {
|
||||
let alive_json = serde_json::json!({
|
||||
"status":"Alive",
|
||||
"status":ServerStatus::Alive,
|
||||
});
|
||||
println!("{}", alive_json);
|
||||
(StatusCode::OK, Json(alive_json))
|
||||
|
@ -23,9 +35,9 @@ async fn alive() -> impl IntoResponse {
|
|||
async fn flip_coin() -> impl IntoResponse {
|
||||
let mut rng = rand::thread_rng();
|
||||
let random:f64 = rng.gen();
|
||||
let mut flip_status:String = "Tail".to_string();
|
||||
let mut flip_status = CoinStatus::Tail;
|
||||
if random > 0.5 {
|
||||
flip_status = "Head".to_string();
|
||||
flip_status = CoinStatus::Head;
|
||||
}
|
||||
let coin_json = serde_json::json!({
|
||||
"status":flip_status,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue