use std::path::PathBuf;
use axum::Router;
use once_cell::sync::Lazy;
pub use logger::Logger;
pub use server::Server;
pub mod application;
pub(crate) mod logger;
mod server;
#[derive(Eq, Hash, PartialEq)]
pub enum ServerTag {
Main,
Metrics,
}
impl ServerTag {
pub fn as_string(&self) -> String {
match self {
ServerTag::Main => "main".to_owned(),
ServerTag::Metrics => "metrics".to_owned(),
}
}
}
pub struct Routes(pub ServerTag, pub Vec<Router>);
pub static BASE_PATH: Lazy<PathBuf> = Lazy::new(|| {
std::env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| {
std::env::current_dir()
.expect("project directory does not exist or permissions are insufficient")
})
});
pub static RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("failed to create tokio runtime")
});
pub fn storage_path(path: &str) -> PathBuf {
let storage_path = std::env::var("STORAGE_PATH").unwrap_or("storage/app".to_owned());
BASE_PATH.join(storage_path).join(path)
}