Setup Store in GLOBALS at start

This commit is contained in:
Mike Dilger committed 2024-02-17 09:53:47 +13:00
1 parent 2b9683404f
commit 42b5042aa6
2 files changed
+9

No files matched your search

+4
View File
@@ -1,15 +1,19 @@
use crate::config::Config;
use crate::store::Store;
use lazy_static::lazy_static;
use std::sync::OnceLock;
use tokio::sync::RwLock;
pub struct Globals {
pub config: RwLock<Config>,
pub store: OnceLock<Store>,
}
lazy_static! {
pub static ref GLOBALS: Globals = {
Globals {
config: RwLock::new(Config::default()),
store: OnceLock::new(),
}
};
}
+5
View File
@@ -9,6 +9,7 @@ pub mod types;
use crate::config::Config;
use crate::error::Error;
use crate::globals::GLOBALS;
use crate::store::Store;
use std::env;
use std::fs::OpenOptions;
use std::io::Read;
@@ -32,6 +33,10 @@ async fn main() -> Result<(), Error> {
let config: Config = ron::from_str(&contents)?;
log::debug!("Loaded config file.");
// Setup store
let store = Store::new(&config.data_directory)?;
let _ = GLOBALS.store.set(store);
// Store config into GLOBALS
*GLOBALS.config.write().await = config;