rieter/server/src/config.rs

46 lines
839 B
Rust
Raw Normal View History

2024-06-13 09:21:56 +02:00
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<Path>) -> Figment {
Figment::new()
.merge(Toml::file(config_file))
.merge(Env::prefixed("RIETER_"))
}
}