aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs48
1 files changed, 0 insertions, 48 deletions
diff --git a/src/config.rs b/src/config.rs
deleted file mode 100644
index c335e8d..0000000
--- a/src/config.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use std::env;
-use anyhow::{Result, Context, anyhow};
-use log::*;
-
-pub struct DiplonatConfig {
- pub private_ip: String,
- pub consul_node_name: String,
- pub consul_url: String,
- pub refresh_time: u32,
- pub expiration_time: u32
-}
-
-pub fn load_env() -> Result<DiplonatConfig> {
- let epi = "DIPLONAT_PRIVATE_IP";
- let ert = "DIPLONAT_REFRESH_TIME";
- let eet = "DIPLONAT_EXPIRATION_TIME";
- let ecnd = "DIPLONAT_CONSUL_NODE_NAME";
- let ecu = "DIPLONAT_CONSUL_URL";
-
- let config = DiplonatConfig {
- consul_url: match env::var(ecu) { Ok(e) => e, Err(_) => "http://127.0.0.1:8500".to_string() },
- private_ip: env::var(epi)
- .with_context(|| format!("{} env var must be defined, eg: 192.168.0.18", epi))?,
- refresh_time: env::var(ert)
- .with_context(|| format!("{} env var must be defined, eg: 60", ert))?
- .parse()
- .with_context(|| format!("{} env var must be an integer, eg: 60", ert))?,
- expiration_time: env::var(eet)
- .with_context(|| format!("{} env var must be defined, eg: 300", eet))?
- .parse()
- .with_context(|| format!("{} env var must be an integer, eg: 300", eet))?,
- consul_node_name: env::var(ecnd)
- .with_context(|| format!("{} env var must be defined", ecnd))?
- };
-
- if config.refresh_time * 2 > config.expiration_time {
- return Err(anyhow!("Expiration time (currently: {}s) must be twice bigger than refresh time (currently: {}s)", config.expiration_time, config.refresh_time))
- }
-
- info!("Consul URL: {}", config.consul_url);
- info!("Consul node name: {}", config.consul_node_name);
- info!("Private IP address: {}", config.private_ip);
- info!("Refresh time: {} seconds", config.refresh_time);
- info!("Expiration time: {} seconds", config.expiration_time);
- return Ok(config);
-}
-
-