add test code to access static global state
This commit is contained in:
parent
fe0e04c69c
commit
c2d9b3914a
28
src/api3.rs
28
src/api3.rs
|
@ -1,6 +1,8 @@
|
||||||
use failure::*;
|
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::schema::*;
|
||||||
use crate::api::router::*;
|
use crate::api::router::*;
|
||||||
|
@ -9,6 +11,29 @@ use serde_json::{json, Value};
|
||||||
pub mod config;
|
pub mod config;
|
||||||
mod version;
|
mod version;
|
||||||
|
|
||||||
|
use crate::backup::datastore::*;
|
||||||
|
|
||||||
|
lazy_static!{
|
||||||
|
static ref datastore_map: Mutex<HashMap<String, Arc<DataStore>>> = Mutex::new(HashMap::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_datastore(name: &str) -> Result<Arc<DataStore>, 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<Value, Error> {
|
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||||
println!("This is a test {}", param);
|
println!("This is a test {}", param);
|
||||||
|
|
||||||
|
@ -23,7 +48,6 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error
|
||||||
if let Some(_force) = param["force"].as_bool() {
|
if let Some(_force) = param["force"].as_bool() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(json!(null))
|
Ok(json!(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue