tina-core 0.0.2

Tina platform
Documentation
//! config mod

use config::Config;
use serde::de::DeserializeOwned;

use super::{data::AppResult, server::application::AppConfig};

pub mod log;
pub mod registry;
pub mod security;
pub mod server;

/// Config 扩展
pub trait ConfigExt {
    /// 获取配置
    fn get_or_default<T: DeserializeOwned + Default>(&self, key: &str) -> T;
}

impl ConfigExt for Config {
    fn get_or_default<T: DeserializeOwned + Default>(&self, key: &str) -> T {
        match self.get(key) {
            Ok(v) => v,
            Err(_) => T::default(),
        }
    }
}

/// 可应用的配置
#[async_trait]
pub trait UpdateableConfig {
    /// 应用更新
    async fn apply(&self, application: &AppConfig) -> AppResult<()>;
}