GLOBALS, and loading config into it

This commit is contained in:
Mike Dilger 2023-10-26 19:04:53 +13:00
parent 07be9a2e40
commit ff0c9ca009
2 changed files with 20 additions and 0 deletions

15
src/globals.rs Normal file
View File

@ -0,0 +1,15 @@
use crate::config::Config;
use lazy_static::lazy_static;
use tokio::sync::RwLock;
pub struct Globals {
pub config: RwLock<Config>,
}
lazy_static! {
pub static ref GLOBALS: Globals = {
Globals {
config: RwLock::new(Config::default()),
}
};
}

View File

@ -1,9 +1,11 @@
pub mod config;
pub mod error;
pub mod globals;
use crate::config::Config;
use crate::error::Error;
use crate::globals::GLOBALS;
use std::env;
use std::fs::OpenOptions;
use std::io::Read;
@ -27,6 +29,9 @@ async fn main() -> Result<(), Error> {
let config: Config = ron::from_str(&contents)?;
log::debug!("Loaded config file.");
// Store config into GLOBALS
*GLOBALS.config.write().await = config;
log::error!("No main yet.");
Ok(())