27 lines
680 B
Rust
27 lines
680 B
Rust
use config::{Config, ConfigError, File};
|
|
use geoffrey_models::models::settings::GeoffreySettings;
|
|
use serde::Deserialize;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct GeoffreyAPIConfig {
|
|
pub server_config: ServerConfig,
|
|
pub geoffrey_settings: GeoffreySettings,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct ServerConfig {
|
|
pub db_path: PathBuf,
|
|
pub host: String,
|
|
pub local_socket: Option<PathBuf>,
|
|
}
|
|
|
|
impl GeoffreyAPIConfig {
|
|
pub fn new(config_path: &Path) -> Result<Self, ConfigError> {
|
|
let mut cfg = Config::new();
|
|
cfg.merge(File::from(config_path.to_path_buf()))?;
|
|
|
|
cfg.try_into()
|
|
}
|
|
}
|