Skip to main content

burncloud_core/
config_manager.rs

1use anyhow::Result;
2use burncloud_common::{load_config, save_config, Config};
3
4pub struct ConfigManager {
5    config: Config,
6    config_path: String,
7}
8
9impl ConfigManager {
10    pub fn new(config_path: String) -> Result<Self> {
11        let config = load_config(&config_path)?;
12        Ok(Self {
13            config,
14            config_path,
15        })
16    }
17
18    pub fn get_config(&self) -> &Config {
19        &self.config
20    }
21
22    pub fn update_config(&mut self, new_config: Config) -> Result<()> {
23        self.config = new_config;
24        save_config(&self.config_path, &self.config)?;
25        Ok(())
26    }
27
28    pub fn get_models_dir(&self) -> &str {
29        &self.config.models_dir
30    }
31
32    pub fn get_server_port(&self) -> u16 {
33        self.config.server_port
34    }
35}