Refactor configuration and main runtime setup.
Renamed `AppConfig` to `Runtime` and updated method names for clarity, replacing `new` with `configure`. Adjusted `main.rs` to use the revised `Runtime` struct and method, simplifying server initialization and aligning terminology.
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
pub struct AppConfig {
|
pub struct Runtime {
|
||||||
pub env_vars: Vec<String>,
|
pub env_vars: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl AppConfig {
|
impl Runtime {
|
||||||
pub fn new() -> Self {
|
pub fn configure() -> Self {
|
||||||
// automatic configuration between local/docker environments
|
// automatic configuration between local/docker environments
|
||||||
match dotenv::dotenv() {
|
match dotenv::dotenv() {
|
||||||
Ok(_) => tracing::debug!("Loaded .env file successfully"),
|
Ok(_) => tracing::debug!("Loaded .env file successfully"),
|
||||||
|
15
src/main.rs
15
src/main.rs
@@ -1,5 +1,4 @@
|
|||||||
// src/main.rs
|
use crate::config::{Runtime};
|
||||||
use crate::config::AppConfig;
|
|
||||||
use crate::routes::create_router;
|
use crate::routes::create_router;
|
||||||
use crate::setup::init_logging;
|
use crate::setup::init_logging;
|
||||||
|
|
||||||
@@ -13,18 +12,14 @@ mod utils;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Initialize logging
|
|
||||||
init_logging();
|
init_logging();
|
||||||
|
|
||||||
// init server configuration
|
Runtime::configure();
|
||||||
let _ = AppConfig::new();
|
|
||||||
|
|
||||||
// Create router with all routes
|
let router = create_router();
|
||||||
let app = create_router();
|
|
||||||
|
|
||||||
// Start core
|
|
||||||
let addr = "0.0.0.0:3006";
|
let addr = "0.0.0.0:3006";
|
||||||
tracing::info!("Attempting to bind core to {}", addr);
|
tracing::info!("Attempting to bind server to {}", addr);
|
||||||
|
|
||||||
let listener = match tokio::net::TcpListener::bind(addr).await {
|
let listener = match tokio::net::TcpListener::bind(addr).await {
|
||||||
Ok(l) => {
|
Ok(l) => {
|
||||||
@@ -38,5 +33,5 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tracing::info!("Server starting on {}", listener.local_addr().unwrap());
|
tracing::info!("Server starting on {}", listener.local_addr().unwrap());
|
||||||
axum::serve(listener, app.into_make_service()).await.unwrap();
|
axum::serve(listener, router.into_make_service()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user