fusion_core/configuration/model/
fusion_setting.rs1use config::{Config, ConfigError};
2use serde::{Deserialize, Serialize};
3
4use super::{AppSetting, LogSetting, SecuritySetting};
5
6#[derive(Clone, Serialize, Deserialize)]
7pub struct FusionSetting {
8 app: AppSetting,
9
10 security: SecuritySetting,
11
12 log: LogSetting,
13}
14
15impl FusionSetting {
16 pub fn app(&self) -> &AppSetting {
17 &self.app
18 }
19
20 pub fn security(&self) -> &SecuritySetting {
21 &self.security
22 }
23
24 pub fn log(&self) -> &LogSetting {
25 &self.log
26 }
27}
28
29impl TryFrom<&Config> for FusionSetting {
30 type Error = ConfigError;
31
32 fn try_from(value: &Config) -> core::result::Result<Self, Self::Error> {
33 match value.get::<FusionSetting>("fusion") {
34 Ok(mut setting) => {
35 if setting.log.log_name.is_none() || setting.log.log_name.iter().any(|s| s.is_empty()) {
36 setting.log.log_name = Some(format!("{}.log", setting.app.name()));
37 }
38 Ok(setting)
39 }
40 other => other,
41 }
42 }
43}