diff --git a/src/api3.rs b/src/api3.rs index 6753615b..2fb3f200 100644 --- a/src/api3.rs +++ b/src/api3.rs @@ -1,6 +1,8 @@ use failure::*; -//use std::collections::HashMap; +use std::collections::HashMap; +use lazy_static::lazy_static; +use std::sync::{Arc, Mutex}; use crate::api::schema::*; use crate::api::router::*; @@ -9,6 +11,29 @@ use serde_json::{json, Value}; pub mod config; mod version; +use crate::backup::datastore::*; + +lazy_static!{ + static ref datastore_map: Mutex>> = Mutex::new(HashMap::new()); +} + +fn lookup_datastore(name: &str) -> Result, Error> { + + let mut map = datastore_map.lock().unwrap(); + + if let Some(datastore) = map.get(name) { + return Ok(datastore.clone()); + } + + if let Ok(datastore) = DataStore::open(name) { + let datastore = Arc::new(datastore); + map.insert(name.to_string(), datastore.clone()); + return Ok(datastore); + } + + bail!("store not found"); +} + fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result { println!("This is a test {}", param); @@ -23,7 +48,6 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result