- add: utils library

- add: packet-service to handle game client packets
- fix: health check for database-service
- fix: health check for auth-service
This commit is contained in:
2024-12-09 23:10:26 -05:00
parent 20e86dd117
commit e5c961d1b4
25 changed files with 1176 additions and 120 deletions

View File

@@ -0,0 +1,48 @@
use serde::Deserialize;
#[derive(Deserialize)]
struct Address {
Address: String,
Port: u16,
}
#[derive(Deserialize)]
struct TaggedAddresses {
lan_ipv4: Address,
wan_ipv4: Address,
}
#[derive(Deserialize)]
struct Weights {
Passing: u8,
Warning: u8,
}
#[derive(Deserialize)]
pub struct Service {
pub ID: String,
pub Service: String,
pub Tags: Vec<String>,
pub Port: u16,
pub Address: String,
pub TaggedAddresses: TaggedAddresses,
pub Weights: Weights,
pub EnableTagOverride: bool,
pub ContentHash: String,
pub Datacenter: String,
}
pub async fn get_service_address(consul_url: &str, service_name: &str) -> Result<(Service), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let consul_service_url = format!("{}/v1/agent/service/{}", consul_url, service_name);
let response = client
.get(&consul_service_url)
.send()
.await?
.error_for_status()?
.json::<Service>()
.await?; // Ensure response is successful
Ok(response)
}