56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
|
|
/// OSIRIS configuration
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct Config {
|
|
/// HeroDB connection configuration
|
|
pub herodb: HeroDbConfig,
|
|
|
|
/// Namespace configurations
|
|
#[serde(default)]
|
|
pub namespaces: HashMap<String, NamespaceConfig>,
|
|
}
|
|
|
|
/// HeroDB connection configuration
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct HeroDbConfig {
|
|
/// HeroDB URL (e.g., "redis://localhost:6379")
|
|
pub url: String,
|
|
}
|
|
|
|
/// Namespace configuration
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct NamespaceConfig {
|
|
/// HeroDB database ID for this namespace
|
|
pub db_id: u16,
|
|
}
|
|
|
|
impl Config {
|
|
/// Get namespace configuration by name
|
|
pub fn get_namespace(&self, name: &str) -> Option<&NamespaceConfig> {
|
|
self.namespaces.get(name)
|
|
}
|
|
|
|
/// Add or update a namespace
|
|
pub fn set_namespace(&mut self, name: String, config: NamespaceConfig) {
|
|
self.namespaces.insert(name, config);
|
|
}
|
|
|
|
/// Remove a namespace
|
|
pub fn remove_namespace(&mut self, name: &str) -> Option<NamespaceConfig> {
|
|
self.namespaces.remove(name)
|
|
}
|
|
|
|
/// Get the next available database ID
|
|
pub fn next_db_id(&self) -> u16 {
|
|
let max_id = self
|
|
.namespaces
|
|
.values()
|
|
.map(|ns| ns.db_id)
|
|
.max()
|
|
.unwrap_or(0);
|
|
max_id + 1
|
|
}
|
|
}
|