use std::sync::Arc;
lazy_static::lazy_static! {
pub(crate) static ref CONFIG_TYPE_TEXT: Arc<String> = Arc::new("text".to_string());
pub(crate) static ref CONFIG_TYPE_JSON: Arc<String> = Arc::new("json".to_string());
pub(crate) static ref CONFIG_TYPE_XML: Arc<String> = Arc::new("xml".to_string());
pub(crate) static ref CONFIG_TYPE_YAML: Arc<String> = Arc::new("yaml".to_string());
pub(crate) static ref CONFIG_TYPE_HTML: Arc<String> = Arc::new("html".to_string());
pub(crate) static ref CONFIG_TYPE_PROPERTIES: Arc<String> = Arc::new("properties".to_string());
pub(crate) static ref CONFIG_TYPE_TOML: Arc<String> = Arc::new("toml".to_string());
}
pub(crate) const MEDIA_TYPE_TEXT_PLAIN: &str = "text/plain;charset=UTF-8";
pub(crate) const MEDIA_TYPE_TEXT_HTML: &str = "text/html;charset=UTF-8";
pub(crate) const MEDIA_TYPE_APPLICATION_JSON: &str = "application/json;charset=UTF-8";
pub(crate) const MEDIA_TYPE_APPLICATION_XML: &str = "application/xml;charset=UTF-8";
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum ConfigType {
Text,
Json,
Xml,
Yaml,
Html,
Properties,
Toml,
}
impl Default for ConfigType {
fn default() -> Self {
Self::Text
}
}
impl ConfigType {
pub fn new_by_value(v: &str) -> Self {
match v.to_lowercase().as_str() {
"json" => Self::Json,
"xml" => Self::Xml,
"yml" => Self::Yaml,
"yaml" => Self::Yaml,
"html" => Self::Html,
"toml" => Self::Toml,
"properties" => Self::Properties,
_ => Self::Text,
}
}
pub fn get_value(&self) -> Arc<String> {
match self {
ConfigType::Text => CONFIG_TYPE_TEXT.clone(),
ConfigType::Json => CONFIG_TYPE_JSON.clone(),
ConfigType::Xml => CONFIG_TYPE_XML.clone(),
ConfigType::Yaml => CONFIG_TYPE_YAML.clone(),
ConfigType::Html => CONFIG_TYPE_HTML.clone(),
ConfigType::Properties => CONFIG_TYPE_PROPERTIES.clone(),
ConfigType::Toml => CONFIG_TYPE_TOML.clone(),
}
}
pub fn get_media_type(&self) -> &'static str {
match self {
ConfigType::Text => MEDIA_TYPE_TEXT_PLAIN,
ConfigType::Json => MEDIA_TYPE_APPLICATION_JSON,
ConfigType::Xml => MEDIA_TYPE_APPLICATION_XML,
ConfigType::Yaml => MEDIA_TYPE_TEXT_PLAIN,
ConfigType::Html => MEDIA_TYPE_TEXT_HTML,
ConfigType::Properties => MEDIA_TYPE_TEXT_PLAIN,
ConfigType::Toml => MEDIA_TYPE_TEXT_PLAIN,
}
}
}