Geoffrey-rs/geoffrey_api/src/config.rs

20 lines
464 B
Rust

use config::{Config, ConfigError, File};
use serde::Deserialize;
use std::path::{Path, PathBuf};
#[derive(Debug, Deserialize, Clone)]
pub struct GeoffreyAPIConfig {
pub db_path: PathBuf,
pub host: String,
pub max_str_len: usize,
}
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()
}
}