use std::path::{Path, PathBuf}; use figment::{ providers::{Env, Format, Toml}, Figment, }; use serde::Deserialize; #[derive(Deserialize)] #[serde(rename_all = "lowercase")] #[serde(tag = "type")] pub enum FsConfig { Local { data_dir: PathBuf }, } #[derive(Deserialize)] #[serde(rename_all = "lowercase")] #[serde(tag = "type")] pub enum DbConfig { Sqlite { path: PathBuf, }, Postgres { host: String, user: String, password: String, }, } #[derive(Deserialize)] pub struct Config { api_key: String, port: u16, log_level: String, fs: FsConfig, db: DbConfig, } impl Config { pub fn figment(config_file: impl AsRef) -> Figment { Figment::new() .merge(Toml::file(config_file)) .merge(Env::prefixed("RIETER_")) } }