move repos into monorepo
This commit is contained in:
55
lib/osiris/core/config/model.rs
Normal file
55
lib/osiris/core/config/model.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user