- add: handle channel list request

- add: handle server select request
- add: handle character list request stub
- add: start health check function for consul
This commit is contained in:
2024-12-13 04:40:07 -05:00
parent 1220d7a031
commit 38ea2ddb71
9 changed files with 133 additions and 49 deletions

View File

@@ -9,3 +9,5 @@ reqwest = { version = "0.12.9", features = ["json"] }
tracing = "0.1"
rand = "0.9.0-beta.1"
uuid = { version = "1.11.0", features = ["v4"] }
warp = "0.3.7"
tokio = "1.41.1"

View File

@@ -1,7 +1,10 @@
use std::collections::HashMap;
use reqwest::Client;
use serde::Serialize;
use std::collections::HashMap;
use std::env;
use std::net::ToSocketAddrs;
use uuid::Uuid;
use warp::Filter;
#[derive(Serialize)]
struct ConsulRegistration {
@@ -71,5 +74,18 @@ pub async fn deregister_service(consul_url: &str, service_id: &str) -> Result<()
.await?
.error_for_status()?; // Ensure response is successful
Ok(())
}
pub async fn start_health_check(service_address: &str) -> Result<(), Box<dyn std::error::Error>> {
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8082".to_string());
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
// Start health-check endpoint
let health_route = warp::path!("health")
.map(|| warp::reply::with_status("OK", warp::http::StatusCode::OK));
tokio::spawn(warp::serve(health_route).run(health_check_endpoint_addr.to_socket_addrs()?.next().unwrap()));
Ok(())
}