- chore: ran cargo fix on the codebase

This commit is contained in:
2025-03-07 21:03:15 -05:00
parent 3b789d0fd4
commit b6f2d3f456
59 changed files with 1324 additions and 523 deletions

View File

@@ -1,27 +1,29 @@
mod character_service;
mod character_db_client;
mod character_service;
pub mod database {
tonic::include_proto!("character_db_api");
}
use crate::character_db_client::CharacterDbClient;
use crate::character_service::character::character_service_server::CharacterServiceServer;
use crate::character_service::MyCharacterService;
use dotenv::dotenv;
use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use std::sync::Arc;
use tokio::{select, signal};
use tracing::{info, Level};
use tracing::Level;
use utils::consul_registration;
use utils::service_discovery::get_service_address;
use crate::character_db_client::CharacterDbClient;
use crate::character_service::character::character_service_server::CharacterServiceServer;
use crate::character_service::MyCharacterService;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
tracing_subscriber::fmt()
.with_max_level(Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string())).unwrap_or_else(|_| Level::INFO))
.with_max_level(
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
.unwrap_or_else(|_| Level::INFO),
)
.init();
// Set the gRPC server address
@@ -31,7 +33,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let consul_url = env::var("CONSUL_URL").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
let service_name = env::var("SERVICE_NAME").unwrap_or_else(|_| "character-service".to_string());
let service_address = env::var("CHARACTER_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
let service_address =
env::var("CHARACTER_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
let service_port = port.clone();
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
@@ -53,7 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
meta,
&health_check_url,
)
.await?;
.await?;
// Start health-check endpoint
consul_registration::start_health_check(addr.as_str()).await?;
@@ -61,10 +64,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let full_addr = format!("{}:{}", &addr, port);
let address = full_addr.parse().expect("Invalid address");
let db_address = db_nodes.get(0).unwrap();
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
let db_url = format!(
"http://{}:{}",
db_address.ServiceAddress, db_address.ServicePort
);
let character_db_client = Arc::new(CharacterDbClient::connect(&db_url).await?);
let character_service = MyCharacterService {
character_db_client
character_db_client,
};
tonic::transport::Server::builder()
@@ -72,9 +78,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.serve(address)
.await?;
utils::signal_handler::wait_for_signal().await;
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
consul_registration::deregister_service(&consul_url, service_id.as_str())
.await
.expect("");
Ok(())
}