mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 18:36:21 +00:00
ref(global) move modules, extract constants
This commit is contained in:
10 files changed
+216
-152
No files matched your search
@@ -0,0 +1,45 @@
|
||||
mod database;
|
||||
pub mod logger;
|
||||
pub mod server;
|
||||
|
||||
use macros::panic_with_log;
|
||||
use std::{env, panic};
|
||||
use tracing::{info, Level};
|
||||
|
||||
pub fn load_env() {
|
||||
if let Some(env_file) = env::args().nth(1) {
|
||||
match dotenv::from_filename(&env_file) {
|
||||
Ok(_) => {
|
||||
println!("[info] env loaded from {}, starting up", env_file);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("[fatal] failed to read {}: {}", env_file, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("[info] no .env file referred, starting up")
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start() {
|
||||
let db_pool = match database::init().await {
|
||||
Ok(pool) => {
|
||||
info!("database connection pool initialized");
|
||||
pool
|
||||
}
|
||||
Err(e) => {
|
||||
panic_with_log!(
|
||||
Level::ERROR,
|
||||
"database connection pool failed to initialize: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
match server::start(db_pool).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
panic_with_log!(Level::ERROR, "server panicked: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user