gdps-server/src/config.rs

35 lines
No EOL
793 B
Rust

use serde::Deserialize;
use std::fs;
use std::sync::LazyLock;
#[derive(Deserialize)]
pub struct Config {
pub general: ConfigGeneral,
pub accounts: ConfigAccounts
}
#[derive(Deserialize)]
pub struct ConfigGeneral {
pub append_path: String,
pub port: u16
}
#[derive(Deserialize)]
pub struct ConfigAccounts {
pub allow_registration: bool
}
impl Config {
pub fn load_from_file(file_path: &str) -> Self {
let toml_str = fs::read_to_string(file_path).expect("Error finding toml config:");
let config: Config = toml::from_str(toml_str.as_str()).expect("Error parsing toml config:");
return config;
}
}
pub static CONFIG: LazyLock<Config> = LazyLock::new(|| {
let config = Config::load_from_file("config.toml");
return config;
});