44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::sync::Mutex;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PortalConfig {
|
|
pub api_base_url: String,
|
|
pub api_key: String,
|
|
pub timeout_secs: u64,
|
|
}
|
|
|
|
impl Default for PortalConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
api_base_url: "http://127.0.0.1:3002".to_string(),
|
|
api_key: "muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69".to_string(),
|
|
timeout_secs: 30,
|
|
}
|
|
}
|
|
}
|
|
|
|
static CONFIG: Mutex<Option<PortalConfig>> = Mutex::new(None);
|
|
|
|
pub fn init_config() {
|
|
let mut config = CONFIG.lock().unwrap();
|
|
if config.is_none() {
|
|
let api_url = std::env::var("MOMENTRY_API_URL")
|
|
.unwrap_or_else(|_| "http://127.0.0.1:3002".to_string());
|
|
let api_key = std::env::var("MOMENTRY_API_KEY").unwrap_or_else(|_| {
|
|
"muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69".to_string()
|
|
});
|
|
|
|
*config = Some(PortalConfig {
|
|
api_base_url: api_url,
|
|
api_key,
|
|
timeout_secs: 30,
|
|
});
|
|
}
|
|
}
|
|
|
|
pub fn get_config() -> PortalConfig {
|
|
let config = CONFIG.lock().unwrap();
|
|
config.clone().unwrap_or_default()
|
|
}
|