Skip to main content

napi_package_template/configration/
mod.rs

1use config::Config;
2mod settings;
3use lazy_static::lazy_static;
4// use crate::error::{ConfigError, Result};
5use serde::de::Deserialize;
6use std::sync::RwLock;
7
8lazy_static! {
9    static ref CONFIG: RwLock<Config> = RwLock::new(settings::get_config());
10}
11
12// pub fn get(property:String) -> String{
13//     CONFIG.lock().unwrap().get(&property).unwrap()
14// }
15
16pub fn get<'de, T: Deserialize<'de>>(key: &str) -> T {
17    CONFIG.read().unwrap().get(key).unwrap()
18}
19
20pub fn get_res<'de, T: Deserialize<'de>>(key: &str) -> Result<T, config::ConfigError> {
21    CONFIG.read().unwrap().get(key)
22}
23