summaryrefslogtreecommitdiff
path: root/dichroism/src/config.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-10-05 22:05:58 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-10-05 22:05:58 -0400
commit743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d (patch)
tree3d393ff1ffd06d1bf470430b2316f46000794806 /dichroism/src/config.rs
parentf8bf353073220ce329d8eb347e3574d5793b6d26 (diff)
downloadtheglassyladies-743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d.tar.xz
theglassyladies-743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d.zip
started work on schema, models, and repos
Diffstat (limited to 'dichroism/src/config.rs')
-rw-r--r--dichroism/src/config.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/dichroism/src/config.rs b/dichroism/src/config.rs
index e5b4046..c3dec51 100644
--- a/dichroism/src/config.rs
+++ b/dichroism/src/config.rs
@@ -1 +1,31 @@
-struct Config {}
+use crate::constants::*;
+use crate::error::DichroismError;
+use crate::result::Result;
+use async_std::fs::metadata;
+use async_std::path::PathBuf;
+use std::env;
+use std::net::SocketAddr;
+
+#[derive(Debug, Clone)]
+pub struct Config {
+ pub db_url: String,
+ pub img_root: PathBuf,
+ pub bind_addr: SocketAddr,
+}
+
+impl Config {
+ pub async fn new_from_env() -> Result<Self> {
+ let img_root = PathBuf::from(env::var(ENV_IMG_ROOT)?);
+ let meta = metadata(&img_root).await?;
+
+ if !meta.is_dir() || meta.permissions().readonly() {
+ return Err(Box::new(DichroismError::InvalidImageRoot));
+ }
+
+ Ok(Config {
+ db_url: env::var(ENV_DB_URL)?,
+ img_root,
+ bind_addr: env::var(ENV_BIND_ADDR)?.parse()?,
+ })
+ }
+}