2026-06-06 16:41:23 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::sync::Arc;
|
2026-06-06 17:04:21 +00:00
|
|
|
use tokio::sync::RwLock;
|
2026-06-06 16:41:23 +00:00
|
|
|
|
|
|
|
|
pub struct RefreshRegistry {
|
|
|
|
|
domains: HashMap<String, Domain>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for RefreshRegistry {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Domain {
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub refresh_interval: std::time::Duration,
|
|
|
|
|
pub data: Arc<RwLock<HashMap<String, serde_json::Value>>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RefreshRegistry {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
domains: HashMap::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn register_domain(&mut self, domain: Domain) {
|
|
|
|
|
self.domains.insert(domain.name.clone(), domain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn get_domain(&self, name: &str) -> Option<&Domain> {
|
|
|
|
|
self.domains.get(name)
|
|
|
|
|
}
|
|
|
|
|
}
|