2024-06-13 09:21:56 +02:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
use figment::{
|
|
|
|
providers::{Env, Format, Toml},
|
|
|
|
Figment,
|
|
|
|
};
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
2024-06-13 18:40:24 +02:00
|
|
|
#[derive(Deserialize, Debug)]
|
2024-06-13 09:21:56 +02:00
|
|
|
#[serde(rename_all = "lowercase")]
|
|
|
|
#[serde(tag = "type")]
|
|
|
|
pub enum FsConfig {
|
|
|
|
Local { data_dir: PathBuf },
|
|
|
|
}
|
|
|
|
|
2024-06-13 18:40:24 +02:00
|
|
|
#[derive(Deserialize, Debug)]
|
2024-06-13 09:21:56 +02:00
|
|
|
#[serde(rename_all = "lowercase")]
|
|
|
|
#[serde(tag = "type")]
|
|
|
|
pub enum DbConfig {
|
|
|
|
Sqlite {
|
2024-06-13 18:40:24 +02:00
|
|
|
db_dir: PathBuf,
|
2024-06-13 09:21:56 +02:00
|
|
|
},
|
|
|
|
Postgres {
|
|
|
|
host: String,
|
|
|
|
user: String,
|
|
|
|
password: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-06-13 18:40:24 +02:00
|
|
|
#[derive(Deserialize, Debug)]
|
2024-06-13 09:21:56 +02:00
|
|
|
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_"))
|
|
|
|
}
|
|
|
|
}
|