diff --git a/app_env/src/config.rs b/app_env/src/config.rs index db44610..e5d827b 100644 --- a/app_env/src/config.rs +++ b/app_env/src/config.rs @@ -4,6 +4,8 @@ use serde::{Serialize,Deserialize,Deserializer}; use std::fmt; +use crate::DataStore; + #[derive(Clone, Debug, Deserialize)] pub struct Notifier { pub name: String, @@ -200,7 +202,8 @@ pub struct Config { pub monitor_rules_file: String, pub monitor_rules_format: String, pub default_lang: String, - pub logs_store: String, + pub logs_store: DataStore, + pub logs_path: String, pub logs_format: String, pub run_schedtasks: bool, pub schedtasks: Vec, @@ -234,6 +237,7 @@ impl Config { let app_home=envmnt::get_or("APP_HOME", "."); let mut app_cfg: Config = cfg; + app_cfg.logs_path=format!("{}/{}",&app_home,&app_cfg.logs_path); app_cfg.cache_path=format!("{}/{}",&app_home,&app_cfg.cache_path); app_cfg.cache_lock_path=format!("{}/{}",&app_home,&app_cfg.cache_lock_path); app_cfg.check_path=format!("{}/{}",&app_home,&app_cfg.check_path); diff --git a/app_env/src/lib.rs b/app_env/src/lib.rs index 5383ffc..538a4a1 100644 --- a/app_env/src/lib.rs +++ b/app_env/src/lib.rs @@ -19,6 +19,7 @@ pub mod appinfo; pub mod config; pub mod module; pub mod profile; +pub mod applogs; use crate::appdata::AppData; @@ -61,6 +62,59 @@ pub async fn get_db_appdata() -> AppData { } */ +#[derive(Clone, Copy, Debug, PartialEq, Deserialize)] +/// `DataStore` options +pub enum DataStore { + File, + Mysql, // (sqlx::MySqlPool), + Postgres, // (sqlx::PgPool), + Sqlite, // (sqlx::SqlitePool), + Redis, // (redis::Client), + Tikv, // (tikv::RawClient), + Slab, // (Storage), + Unknown, +} + +pub type OptionDataStore = Option; + +impl Default for DataStore { + fn default() -> Self { + DataStore::Unknown + } +} +impl DataStore { + /// Get `DataStore`from String to enum + #[must_use] + pub fn get_from(str: String) -> DataStore { + match str.as_str() { + "file" | "File" => DataStore::File, + "mysql" | "Mysql" | "MySql" => DataStore::Mysql, + "postgres" | "Postgres" | "pg" => DataStore::Postgres, + "sqlite" | "Sqlite" => DataStore::Sqlite, + "redis" | "Redis" => DataStore::Redis, + "tikv" | "Tikv" => DataStore::Tikv, + "slab" | "Slab" => DataStore::Slab, + _ => DataStore::Unknown, + } + } +} + +#[allow(clippy::pattern_type_mismatch)] +impl fmt::Display for DataStore { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + DataStore::File => write!(f, "file"), + DataStore::Mysql => write!(f, "mysql"), + DataStore::Postgres => write!(f, "postgres"), + DataStore::Sqlite => write!(f, "sqlite"), + DataStore::Redis => write!(f, "redis"), + DataStore::Tikv => write!(f, "tikv"), + DataStore::Slab => write!(f, "slab"), + DataStore::Unknown => write!(f, "Unknown"), + } + } +} + #[derive(Clone, Copy, Debug, PartialEq)] /// `DataStore` options pub enum AppRunMode {