2024-12-01 22:17:38 +03:00
|
|
|
pub mod feature;
|
2024-11-26 22:30:25 +03:00
|
|
|
pub mod database;
|
2024-11-29 20:31:02 +03:00
|
|
|
pub mod utils;
|
|
|
|
|
|
|
|
use utils::naive_toml_parser;
|
|
|
|
|
|
|
|
const DATABASE_CONFIG_FILE_LOCATION: &str = "./configs/database_config.toml";
|
|
|
|
const SERVER_CONFIG_FILE_LOCATION: &str = "./configs/server_config.toml";
|
2024-11-26 22:30:25 +03:00
|
|
|
|
2024-11-29 19:53:50 +03:00
|
|
|
#[derive(Debug)]
|
2024-11-26 22:30:25 +03:00
|
|
|
pub struct DatabaseConfig {
|
|
|
|
pub address: String,
|
|
|
|
pub username: String,
|
|
|
|
pub password: String,
|
|
|
|
pub namespace: String,
|
|
|
|
pub database: String,
|
|
|
|
}
|
|
|
|
impl Default for DatabaseConfig {
|
|
|
|
fn default() -> Self {
|
2024-11-29 20:31:02 +03:00
|
|
|
let (header, mut database_configs) = naive_toml_parser(DATABASE_CONFIG_FILE_LOCATION);
|
2024-11-29 19:53:50 +03:00
|
|
|
|
2024-11-29 20:31:02 +03:00
|
|
|
if header == "[database_config]" {
|
2024-11-26 22:30:25 +03:00
|
|
|
Self {
|
2024-11-29 20:31:02 +03:00
|
|
|
database: database_configs.pop().unwrap(),
|
|
|
|
namespace: database_configs.pop().unwrap(),
|
|
|
|
password: database_configs.pop().unwrap(),
|
|
|
|
username: database_configs.pop().unwrap(),
|
|
|
|
address: database_configs.pop().unwrap(),
|
2024-11-26 22:30:25 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
panic!("Database Config File Must Include [database_config] at the First Line")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-29 19:53:50 +03:00
|
|
|
#[derive(Debug)]
|
2024-11-26 22:30:25 +03:00
|
|
|
pub struct ServerConfig {
|
|
|
|
pub address: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ServerConfig {
|
|
|
|
fn default() -> Self {
|
2024-11-29 20:31:02 +03:00
|
|
|
let (header, mut server_configs) = naive_toml_parser(SERVER_CONFIG_FILE_LOCATION);
|
|
|
|
|
|
|
|
if header == "[server_config]" {
|
2024-11-26 22:30:25 +03:00
|
|
|
Self {
|
2024-11-29 20:31:02 +03:00
|
|
|
address: server_configs.pop().unwrap(),
|
2024-11-26 22:30:25 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
panic!("Server Config File Must Include [server_config] at the First Line")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|