myc_core/models/
config.rs1use super::{account_life_cycle_config::AccountLifeCycle, WebhookConfig};
2
3use myc_config::load_config_from_file;
4use mycelium_base::utils::errors::{creation_err, MappedErrors};
5use serde::Deserialize;
6use std::path::PathBuf;
7
8#[derive(Clone, Debug, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct CoreConfig {
11 pub account_life_cycle: AccountLifeCycle,
12 pub webhook: WebhookConfig,
13}
14
15#[derive(Clone, Debug, Deserialize)]
16#[serde(rename_all = "camelCase")]
17struct TmpConfig {
18 core: CoreConfig,
19}
20
21impl CoreConfig {
22 pub fn from_default_config_file(
23 file: PathBuf,
24 ) -> Result<Self, MappedErrors> {
25 if !file.exists() {
26 return creation_err(format!(
27 "Could not find config file: {}",
28 file.to_str().unwrap()
29 ))
30 .as_error();
31 }
32
33 match load_config_from_file::<TmpConfig>(file) {
34 Ok(config) => Ok(config.core),
35 Err(err) => Err(err),
36 }
37 }
38}