Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ itertools = "0.10.5"
flate2 = "1.0.25"
csv = "1.1.6"
fs_extra = "1.3.0"
lazy_static = "1.4.0"
config = "0.13.3"
# spinners = "4.1.0"
27 changes: 27 additions & 0 deletions config/Default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


[infer]
min_domain_occurs = 100
max_ns = 5
iri_max_length = 200
min_ns_size = 1000
iri_trie_size = 1_000_000
# 2 MIN_DOMAIN_OCCURS
# 4 MAX_NS
# 3 IRI_MAX_LENGTH
# 8 MIN_NS_SIZE
# 3 IRI_TRIE_SIZE


[community]
url = "https://raw.githubusercontent.com/linkml/prefixmaps/main/src/prefixmaps/data/merged.csv"
dir = "cache"
path = "cache/prefixmap.json"
# 4 PV_PATH
# 2 PV_URL
# 2 PV_DIR


[visulization]
render_dir = "chilon-viz"
# 5 RENDER_DIR
66 changes: 66 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use config::{Config, ConfigError, Environment, File};

#[derive(Debug, Deserialize, Clone)]
pub struct Infer {
pub min_domain_occurs: i32,
pub max_ns: i32,
pub iri_max_length: i32,
pub min_ns_size: i32,
pub iri_trie_size: i32,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Community {
pub url: String,
pub dir: String,
pub path: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Visualization {
pub render_dir: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Settings {
pub infer: Infer,
pub community: Community,
pub visualization: Visualization,
pub env: ENV,
}

const CONFIG_FILE_PATH: &str = "./config/Default.toml";
const CONFIG_FILE_PREFIX: &str = "./config/";

#[derive(Clone, Debug, Deserialize)]
pub enum ENV {
Development,
Testing,
Production,
}

impl fmt::Display for ENV {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ENV::Development => write!(f, "Development"),
ENV::Testing => write!(f, "Testing"),
ENV::Production => write!(f, "Production"),
}
}
}

impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let env = std::env::var("RUN_ENV").unwrap_or_else(|_| "Development".into());
let mut s = Config::new();
s.set("env", env.clone())?;

s.merge(File::with_name(CONFIG_FILE_PATH))?;
s.merge(File::with_name(&format!("{}{}", CONFIG_FILE_PREFIX, env)))?;

// This makes it so "EA_SERVER__PORT overrides server.port
s.merge(Environment::with_prefix("ea").separator("__"))?;

s.try_into()
}
}