- add: initial database and auth services

This commit is contained in:
2024-11-25 20:45:16 -05:00
parent 6a35b5b373
commit 3ff22c9a5b
24 changed files with 817 additions and 1 deletions

45
auth-service/src/main.rs Normal file
View File

@@ -0,0 +1,45 @@
use dotenv::dotenv;
use std::env;
use tonic::transport::Server;
use auth_service::grpc::MyAuthService;
use auth_service::database_client::DatabaseClient;
use auth_service::auth::auth_service_server::AuthServiceServer;
pub mod auth {
tonic::include_proto!("auth"); // Path matches the package name in auth.proto
}
pub mod database {
tonic::include_proto!("database"); // Matches package name in database.proto
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load environment variables from .env
dotenv().ok();
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_thread_names(true)
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
.init();
// Set the gRPC server address
let addr = env::var("AUTH_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1:50051".to_string());
let db_addr = env::var("DATABASE_SERVICE_ADDR").unwrap_or_else(|_| "http://127.0.0.1:50052".to_string());
let database_client = DatabaseClient::connect(&db_addr).await?;
let addr = addr.parse().expect("Invalid address");
let auth_service = MyAuthService {
db_client: database_client,
};
println!("Authentication Service running on {}", addr);
// Start the gRPC server
Server::builder()
.add_service(AuthServiceServer::new(auth_service))
.serve(addr)
.await?;
Ok(())
}